1 require File.dirname(__FILE__) + '/../../../spec_helper'
2 require 'hpricot' # Needed to compare generated with wanted HTML
3 require 'spec/runner/formatter/html_formatter'
8 describe HtmlFormatter do
9 ['--diff', '--dry-run'].each do |opt|
14 it "should produce HTML identical to the one we designed manually with #{opt}" do
15 root = File.expand_path(File.dirname(__FILE__) + '/../../../..')
16 suffix = jruby? ? '-jruby' : ''
17 expected_file = File.dirname(__FILE__) + "/html_formatted-#{::VERSION}#{suffix}.html"
18 raise "There is no HTML file with expected content for this platform: #{expected_file}" unless File.file?(expected_file)
19 expected_html = File.read(expected_file)
21 raise "There should be no absolute paths in html_formatted.html!!" if (expected_html =~ /\/Users/n || expected_html =~ /\/home/n)
25 args = ['failing_examples/mocking_example.rb', 'failing_examples/diffing_spec.rb', 'examples/pure/stubbing_example.rb', 'examples/pure/pending_example.rb', '--format', 'html', opt]
29 OptionParser.parse(args, err, out)
32 seconds = /\d+\.\d+ seconds/
33 html = out.string.gsub seconds, 'x seconds'
34 expected_html.gsub! seconds, 'x seconds'
37 # Uncomment this line temporarily in order to overwrite the expected with actual.
39 # File.open(expected_file, 'w') {|io| io.write(html)}
42 backtraces = doc.search("div.backtrace").collect {|e| e.at("/pre").inner_html}
43 doc.search("div.backtrace").remove
45 expected_doc = Hpricot(expected_html)
46 expected_backtraces = expected_doc.search("div.backtrace").collect {|e| e.at("/pre").inner_html}
47 expected_doc.search("div.backtrace").remove
49 doc.inner_html.should == expected_doc.inner_html
51 expected_backtraces.each_with_index do |expected_line, i|
52 expected_path, expected_line_number, expected_suffix = expected_line.split(':')
53 actual_path, actual_line_number, actual_suffix = backtraces[i].split(':')
54 File.expand_path(actual_path).should == File.expand_path(expected_path)
55 actual_line_number.should == expected_line_number
58 html.should =~ /This was a dry-run/m