1 require File.dirname(__FILE__) + '/../../../spec_helper'
2 require 'hpricot' # Needed to compare generated with wanted HTML
3 require 'spec/runner/formatter/text_mate_formatter'
8 describe TextMateFormatter do
9 attr_reader :root, :suffix, :expected_file
11 @root = File.expand_path(File.dirname(__FILE__) + '/../../../..')
12 @suffix = jruby? ? '-jruby' : ''
13 @expected_file = File.dirname(__FILE__) + "/text_mate_formatted-#{::VERSION}#{suffix}.html"
20 def produces_html_identical_to_manually_designed_document(opt)
21 root = File.expand_path(File.dirname(__FILE__) + '/../../../..')
25 'failing_examples/mocking_example.rb',
26 'failing_examples/diffing_spec.rb',
27 'examples/pure/stubbing_example.rb',
28 'examples/pure/pending_example.rb',
35 options = ::Spec::Runner::OptionParser.parse(args, err, out)
36 Spec::Runner::CommandLine.run(options)
42 # # Uncomment this spec temporarily in order to overwrite the expected with actual.
44 # describe TextMateFormatter, "functional spec file generator" do
45 # it "generates a new comparison file" do
47 # args = ['failing_examples/mocking_example.rb', 'failing_examples/diffing_spec.rb', 'examples/pure/stubbing_example.rb', 'examples/pure/pending_example.rb', '--format', 'textmate', '--diff']
50 # Spec::Runner::CommandLine.run(
51 # ::Spec::Runner::OptionParser.parse(args, err, out)
54 # seconds = /\d+\.\d+ seconds/
55 # html = out.string.gsub seconds, 'x seconds'
57 # File.open(expected_file, 'w') {|io| io.write(html)}
62 describe "functional spec using --diff" do
63 it "should produce HTML identical to the one we designed manually with --diff" do
64 produces_html_identical_to_manually_designed_document("--diff") do |html|
65 suffix = jruby? ? '-jruby' : ''
66 expected_file = File.dirname(__FILE__) + "/text_mate_formatted-#{::VERSION}#{suffix}.html"
67 unless File.file?(expected_file)
68 raise "There is no HTML file with expected content for this platform: #{expected_file}"
70 expected_html = File.read(expected_file)
72 seconds = /\d+\.\d+ seconds/
73 html.gsub! seconds, 'x seconds'
74 expected_html.gsub! seconds, 'x seconds'
77 backtraces = doc.search("div.backtrace/a")
78 doc.search("div.backtrace").remove
80 expected_doc = Hpricot(expected_html)
81 expected_doc.search("div.backtrace").remove
83 doc.inner_html.should == expected_doc.inner_html
85 backtraces.each do |backtrace_link|
86 backtrace_link[:href].should include("txmt://open?url=")
93 describe "functional spec using --dry-run" do
94 it "should produce HTML identical to the one we designed manually with --dry-run" do
95 produces_html_identical_to_manually_designed_document("--dry-run") do |html, expected_html|
96 html.should =~ /This was a dry-run/m