Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / spec / spec / runner / reporter_spec.rb
blobf067bce0325ee68094b884d7f9821b58168d0206
1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
3 module Spec
4   module Runner
5     
6     module ReporterSpecHelper
7       def setup
8         @io = StringIO.new
9         @backtrace_tweaker = stub("backtrace tweaker", :tweak_backtrace => nil)
10         @formatter = mock("formatter")
11         @reporter = Reporter.new([@formatter], @backtrace_tweaker)
12       end
14       def failure
15         Mocks::DuckTypeArgConstraint.new(:header, :exception)
16       end
17     end
18     
19     describe Reporter do
20       include ReporterSpecHelper
21       before(:each) {setup}
22       
23       it "should tell formatter when behaviour is added" do
24         @formatter.should_receive(:add_behaviour).with("behaviour")
25         @reporter.add_behaviour("behaviour")
26       end
28       it "should handle multiple behaviours with same name" do
29         @formatter.should_receive(:add_behaviour).exactly(3).times
30         @formatter.should_receive(:example_started).exactly(3).times
31         @formatter.should_receive(:example_passed).exactly(3).times
32         @formatter.should_receive(:start_dump)
33         @formatter.should_receive(:dump_summary).with(anything(), 3, 0, 0)
34         @reporter.add_behaviour("behaviour")
35         @reporter.example_started("spec 1")
36         @reporter.example_finished("spec 1")
37         @reporter.add_behaviour("behaviour")
38         @reporter.example_started("spec 2")
39         @reporter.example_finished("spec 2")
40         @reporter.add_behaviour("behaviour")
41         @reporter.example_started("spec 3")
42         @reporter.example_finished("spec 3")
43         @reporter.dump
44       end
46       it "should handle multiple examples with the same name" do
47         error=RuntimeError.new
48         @formatter.should_receive(:add_behaviour).exactly(2).times
49         @formatter.should_receive(:example_passed).with("example").exactly(2).times
50         @formatter.should_receive(:example_failed).with("example", 1, failure)
51         @formatter.should_receive(:example_failed).with("example", 2, failure)
52         @formatter.should_receive(:dump_failure).exactly(2).times
53         @formatter.should_receive(:start_dump)
54         @formatter.should_receive(:dump_summary).with(anything(), 4, 2, 0)
55         @backtrace_tweaker.should_receive(:tweak_backtrace).twice
56         @reporter.add_behaviour("behaviour")
57         @reporter.example_finished("example")
58         @reporter.example_finished("example", error)
59         @reporter.add_behaviour("behaviour")
60         @reporter.example_finished("example")
61         @reporter.example_finished("example", error)
62         @reporter.dump
63       end
65       it "should push stats to formatter even with no data" do
66         @formatter.should_receive(:start_dump)
67         @formatter.should_receive(:dump_summary).with(anything(), 0, 0, 0)
68         @reporter.dump
69       end
70       
71       it "should push time to formatter" do
72         @formatter.should_receive(:start).with(5)
73         @formatter.should_receive(:start_dump)
74         @formatter.should_receive(:dump_summary) do |time, a, b|
75           time.to_s.should match(/[0-9].[0-9|e|-]+/)
76         end
77         @reporter.start(5)
78         @reporter.end
79         @reporter.dump
80       end
81     end
82     
83     describe Reporter, " reporting one passing example" do
84       include ReporterSpecHelper
85       before(:each) {setup}
87       it "should tell formatter example passed" do
88         @formatter.should_receive(:example_passed)
89         @reporter.example_finished("example")
90       end
91       
92       it "should not delegate to backtrace tweaker" do
93         @formatter.should_receive(:example_passed)
94         @backtrace_tweaker.should_not_receive(:tweak_backtrace)
95         @reporter.example_finished("example")
96       end
98       it "should account for passing example in stats" do
99         @formatter.should_receive(:example_passed)
100         @formatter.should_receive(:start_dump)
101         @formatter.should_receive(:dump_summary).with(anything(), 1, 0, 0)
102         @reporter.example_finished("example")
103         @reporter.dump
104       end
105     end
107     describe Reporter, " reporting one failing example" do
108       include ReporterSpecHelper
109       before(:each) {setup}
111       it "should tell formatter that example failed" do
112         @formatter.should_receive(:example_failed)
113         @reporter.example_finished("example", RuntimeError.new)
114       end
115       
116       it "should delegate to backtrace tweaker" do
117         @formatter.should_receive(:example_failed)
118         @backtrace_tweaker.should_receive(:tweak_backtrace)
119         @reporter.example_finished("spec", RuntimeError.new)
120       end
122       it "should account for failing example in stats" do
123         @formatter.should_receive(:add_behaviour)
124         @formatter.should_receive(:example_failed).with("example", 1, failure)
125         @formatter.should_receive(:start_dump)
126         @formatter.should_receive(:dump_failure).with(1, anything())
127         @formatter.should_receive(:dump_summary).with(anything(), 1, 1, 0)
128         @reporter.add_behaviour("behaviour")
129         @reporter.example_finished("example", RuntimeError.new)
130         @reporter.dump
131       end
132       
133     end
134     
135     describe Reporter, " reporting one not implemented example" do
136       include ReporterSpecHelper
137       before(:each) {setup}
139       it "should tell formatter example passed" do
140         @formatter.should_receive(:example_not_implemented)
141         @reporter.example_finished("example", nil, nil, true)
142       end
144       it "should account for not implemented example in stats" do
145         @formatter.should_receive(:example_not_implemented)
146         @formatter.should_receive(:start_dump)
147         @formatter.should_receive(:dump_summary).with(anything(), 1, 0, 1)
148         @reporter.example_finished("example", nil, nil, true)
149         @reporter.dump
150       end
151     end
152   end