changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/runner/formatter/html_formatter_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + '/../../../spec_helper'
2require 'hpricot' # Needed to compare generated with wanted HTML
3require 'spec/runner/formatter/html_formatter'
4
5module Spec
6 module Runner
7 module Formatter
8 describe HtmlFormatter do
9 ['--diff', '--dry-run'].each do |opt|
10 def jruby?
11 PLATFORM == 'java'
12 end
13
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)
20 unless jruby?
21 raise "There should be no absolute paths in html_formatted.html!!" if (expected_html =~ /\/Users/n || expected_html =~ /\/home/n)
22 end
23
24 Dir.chdir(root) do
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]
26 err = StringIO.new
27 out = StringIO.new
28 CommandLine.run(
29 OptionParser.parse(args, err, out)
30 )
31
32 seconds = /\d+\.\d+ seconds/
33 html = out.string.gsub seconds, 'x seconds'
34 expected_html.gsub! seconds, 'x seconds'
35
36 if opt == '--diff'
37 # Uncomment this line temporarily in order to overwrite the expected with actual.
38 # Use with care!!!
39 # File.open(expected_file, 'w') {|io| io.write(html)}
40
41 doc = Hpricot(html)
42 backtraces = doc.search("div.backtrace").collect {|e| e.at("/pre").inner_html}
43 doc.search("div.backtrace").remove
44
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
48
49 doc.inner_html.should == expected_doc.inner_html
50
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
56 end
57 else
58 html.should =~ /This was a dry-run/m
59 end
60 end
61 end
62 end
63 end
64 end
65 end
66end