changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/runner/formatter/spec_mate_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/text_mate_formatter'
4
5module Spec
6 module Runner
7 module Formatter
8 describe TextMateFormatter do
9 attr_reader :root, :suffix, :expected_file
10 before do
11 @root = File.expand_path(File.dirname(__FILE__) + '/../../../..')
12 @suffix = jruby? ? '-jruby' : ''
13 @expected_file = File.dirname(__FILE__) + "/text_mate_formatted-#{::VERSION}#{suffix}.html"
14 end
15
16 def jruby?
17 PLATFORM == 'java'
18 end
19
20 def produces_html_identical_to_manually_designed_document(opt)
21 root = File.expand_path(File.dirname(__FILE__) + '/../../../..')
22
23 Dir.chdir(root) do
24 args = [
25 'failing_examples/mocking_example.rb',
26 'failing_examples/diffing_spec.rb',
27 'examples/pure/stubbing_example.rb',
28 'examples/pure/pending_example.rb',
29 '--format',
30 'textmate',
31 opt
32 ]
33 err = StringIO.new
34 out = StringIO.new
35 options = ::Spec::Runner::OptionParser.parse(args, err, out)
36 Spec::Runner::CommandLine.run(options)
37
38 yield(out.string)
39 end
40 end
41
42 # # Uncomment this spec temporarily in order to overwrite the expected with actual.
43 # # Use with care!!!
44 # describe TextMateFormatter, "functional spec file generator" do
45 # it "generates a new comparison file" do
46 # Dir.chdir(root) 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']
48 # err = StringIO.new
49 # out = StringIO.new
50 # Spec::Runner::CommandLine.run(
51 # ::Spec::Runner::OptionParser.parse(args, err, out)
52 # )
53 #
54 # seconds = /\d+\.\d+ seconds/
55 # html = out.string.gsub seconds, 'x seconds'
56 #
57 # File.open(expected_file, 'w') {|io| io.write(html)}
58 # end
59 # end
60 # end
61
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}"
69 end
70 expected_html = File.read(expected_file)
71
72 seconds = /\d+\.\d+ seconds/
73 html.gsub! seconds, 'x seconds'
74 expected_html.gsub! seconds, 'x seconds'
75
76 doc = Hpricot(html)
77 backtraces = doc.search("div.backtrace/a")
78 doc.search("div.backtrace").remove
79
80 expected_doc = Hpricot(expected_html)
81 expected_doc.search("div.backtrace").remove
82
83 doc.inner_html.should == expected_doc.inner_html
84
85 backtraces.each do |backtrace_link|
86 backtrace_link[:href].should include("txmt://open?url=")
87 end
88 end
89 end
90
91 end
92
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
97 end
98 end
99 end
100 end
101 end
102 end
103end