Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / rspec / spec / spec / runner / reporter_spec.rb
blobbe686ba10966228cfa0cf54ee6aed913bb967de7
1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
3 module Spec
4   module Runner
5     
6     ReporterSpecHelper = describe "reporter spec helpers", :shared => true do
7       before(:each) do
8         @io = StringIO.new
9         @options = Options.new(StringIO.new, @io)
10         @backtrace_tweaker = stub("backtrace tweaker", :tweak_backtrace => nil)
11         @options.backtrace_tweaker = @backtrace_tweaker
12         @formatter = mock("formatter")
13         @options.formatters << @formatter
14         @reporter = Reporter.new(@options)
15       end
17       def failure
18         Mocks::DuckTypeArgConstraint.new(:header, :exception)
19       end
20       
21       def description(s)
22         Spec::Example::ExampleGroupDescription.new(s)
23       end
24     end
25     
26     describe Reporter do
27       include ReporterSpecHelper
28       
29       it "should assign itself as the reporter to options" do
30         @options.reporter.should equal(@reporter)
31       end
32       
33       it "should tell formatter when behaviour is added" do
34         @formatter.should_receive(:add_example_group).with(description("behaviour"))
35         @reporter.add_example_group(description("behaviour"))
36       end
38       it "should handle multiple behaviours with same name" do
39         @formatter.should_receive(:add_example_group).exactly(3).times
40         @formatter.should_receive(:example_started).exactly(3).times
41         @formatter.should_receive(:example_passed).exactly(3).times
42         @formatter.should_receive(:start_dump)
43         @formatter.should_receive(:dump_pending)
44         @formatter.should_receive(:close).with(no_args)
45         @formatter.should_receive(:dump_summary).with(anything(), 3, 0, 0)
46         @reporter.add_example_group(description("behaviour"))
47         @reporter.example_started("spec 1")
48         @reporter.example_finished("spec 1")
49         @reporter.add_example_group(description("behaviour"))
50         @reporter.example_started("spec 2")
51         @reporter.example_finished("spec 2")
52         @reporter.add_example_group(description("behaviour"))
53         @reporter.example_started("spec 3")
54         @reporter.example_finished("spec 3")
55         @reporter.dump
56       end
58       it "should handle multiple examples with the same name" do
59         error=RuntimeError.new
60         @formatter.should_receive(:add_example_group).exactly(2).times
61         @formatter.should_receive(:example_passed).with("example").exactly(2).times
62         @formatter.should_receive(:example_failed).with("example", 1, failure)
63         @formatter.should_receive(:example_failed).with("example", 2, failure)
64         @formatter.should_receive(:dump_failure).exactly(2).times
65         @formatter.should_receive(:start_dump)
66         @formatter.should_receive(:dump_pending)
67         @formatter.should_receive(:close).with(no_args)
68         @formatter.should_receive(:dump_summary).with(anything(), 4, 2, 0)
69         @backtrace_tweaker.should_receive(:tweak_backtrace).twice
70         @reporter.add_example_group(description("behaviour"))
71         @reporter.example_finished("example")
72         @reporter.example_finished("example", error)
73         @reporter.add_example_group(description("behaviour"))
74         @reporter.example_finished("example")
75         @reporter.example_finished("example", error)
76         @reporter.dump
77       end
79       it "should push stats to formatter even with no data" do
80         @formatter.should_receive(:start_dump)
81         @formatter.should_receive(:dump_pending)
82         @formatter.should_receive(:dump_summary).with(anything(), 0, 0, 0)
83         @formatter.should_receive(:close).with(no_args)
84         @reporter.dump
85       end
86       
87       it "should push time to formatter" do
88         @formatter.should_receive(:start).with(5)
89         @formatter.should_receive(:start_dump)
90         @formatter.should_receive(:dump_pending)
91         @formatter.should_receive(:close).with(no_args)
92         @formatter.should_receive(:dump_summary) do |time, a, b|
93           time.to_s.should match(/[0-9].[0-9|e|-]+/)
94         end
95         @reporter.start(5)
96         @reporter.end
97         @reporter.dump
98       end
99     end
100     
101     describe Reporter, "reporting one passing example" do
102       include ReporterSpecHelper
104       it "should tell formatter example passed" do
105         @formatter.should_receive(:example_passed)
106         @reporter.example_finished("example")
107       end
108       
109       it "should not delegate to backtrace tweaker" do
110         @formatter.should_receive(:example_passed)
111         @backtrace_tweaker.should_not_receive(:tweak_backtrace)
112         @reporter.example_finished("example")
113       end
115       it "should account for passing example in stats" do
116         @formatter.should_receive(:example_passed)
117         @formatter.should_receive(:start_dump)
118         @formatter.should_receive(:dump_pending)
119         @formatter.should_receive(:dump_summary).with(anything(), 1, 0, 0)
120         @formatter.should_receive(:close).with(no_args)
121         @reporter.example_finished("example")
122         @reporter.dump
123       end
124     end
126     describe Reporter, "reporting one failing example" do
127       include ReporterSpecHelper
129       it "should tell formatter that example failed" do
130         @formatter.should_receive(:example_failed)
131         @reporter.example_finished("example", RuntimeError.new)
132       end
133       
134       it "should delegate to backtrace tweaker" do
135         @formatter.should_receive(:example_failed)
136         @backtrace_tweaker.should_receive(:tweak_backtrace)
137         @reporter.example_finished("spec", RuntimeError.new)
138       end
140       it "should account for failing example in stats" do
141         @formatter.should_receive(:add_example_group)
142         @formatter.should_receive(:example_failed).with("example", 1, failure)
143         @formatter.should_receive(:start_dump)
144         @formatter.should_receive(:dump_pending)
145         @formatter.should_receive(:dump_failure).with(1, anything())
146         @formatter.should_receive(:dump_summary).with(anything(), 1, 1, 0)
147         @formatter.should_receive(:close).with(no_args)
148         @reporter.add_example_group(description("behaviour"))
149         @reporter.example_finished("example", RuntimeError.new)
150         @reporter.dump
151       end
152       
153     end
154     
155     describe Reporter, "reporting one pending example (ExamplePendingError)" do
156       include ReporterSpecHelper
158       it "should tell formatter example is pending" do
159         @formatter.should_receive(:example_pending).with(description("behaviour"), "example", "reason")
160         @formatter.should_receive(:add_example_group).with(description("behaviour"))
161         @reporter.add_example_group(description('behaviour'))
162         @reporter.example_finished("example", Spec::Example::ExamplePendingError.new("reason"), nil, false)
163       end
165       it "should account for pending example in stats" do
166         @formatter.should_receive(:example_pending).with(description("behaviour"), "example", "reason")
167         @formatter.should_receive(:start_dump)
168         @formatter.should_receive(:dump_pending)
169         @formatter.should_receive(:dump_summary).with(anything(), 1, 0, 1)
170         @formatter.should_receive(:close).with(no_args)
171         @formatter.should_receive(:add_example_group).with(description("behaviour"))
172         @reporter.add_example_group(description('behaviour'))
173         @reporter.example_finished("example", Spec::Example::ExamplePendingError.new("reason"), nil, false)
174         @reporter.dump
175       end
176     end
178     describe Reporter, "reporting one pending example (PendingExampleFixedError)" do
179       include ReporterSpecHelper
181       it "should tell formatter pending example is fixed" do
182         @formatter.should_receive(:example_failed) do |name, counter, failure|
183           failure.header.should == "'behaviour example' FIXED"
184         end
185         @formatter.should_receive(:add_example_group).with(description("behaviour"))
186         @reporter.add_example_group(description('behaviour'))
187         @reporter.example_finished("example", Spec::Example::PendingExampleFixedError.new("reason"), nil, false)
188       end
189     end
190   end