1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
6 module ReporterSpecHelper
9 @backtrace_tweaker = stub("backtrace tweaker", :tweak_backtrace => nil)
10 @formatter = mock("formatter")
11 @reporter = Reporter.new([@formatter], @backtrace_tweaker)
15 Mocks::DuckTypeArgConstraint.new(:header, :exception)
20 include ReporterSpecHelper
23 it "should tell formatter when behaviour is added" do
24 @formatter.should_receive(:add_behaviour).with("behaviour")
25 @reporter.add_behaviour("behaviour")
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")
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)
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)
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|-]+/)
83 describe Reporter, " reporting one passing example" do
84 include ReporterSpecHelper
87 it "should tell formatter example passed" do
88 @formatter.should_receive(:example_passed)
89 @reporter.example_finished("example")
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")
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")
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)
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)
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)
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)
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)