changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/runner/reporter_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.rb'
2
3module Spec
4 module Runner
5 describe Reporter do
6 attr_reader :formatter_output, :options, :backtrace_tweaker, :formatter, :reporter, :example_group
7 before(:each) do
8 @formatter_output = StringIO.new
9 @options = Options.new(StringIO.new, StringIO.new)
10 @backtrace_tweaker = stub("backtrace tweaker", :tweak_backtrace => nil)
11 options.backtrace_tweaker = backtrace_tweaker
12 @formatter = ::Spec::Runner::Formatter::BaseTextFormatter.new(options, formatter_output)
13 options.formatters << formatter
14 @reporter = Reporter.new(options)
15 @example_group = create_example_group("example_group")
16 reporter.add_example_group example_group
17 end
18
19 def failure
20 Mocks::DuckTypeArgConstraint.new(:header, :exception)
21 end
22
23 def create_example_group(description_text)
24 example_group = Class.new(Spec::Example::ExampleGroup)
25 example_group.describe description_text
26 example_group
27 end
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 example_group is added" do
34 formatter.should_receive(:add_example_group).with(example_group)
35 reporter.add_example_group(example_group)
36 end
37
38 it "should handle multiple example_groups 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(create_example_group("example_group"))
47 reporter.example_started("spec 1")
48 reporter.example_finished("spec 1")
49 reporter.add_example_group(create_example_group("example_group"))
50 reporter.example_started("spec 2")
51 reporter.example_finished("spec 2")
52 reporter.add_example_group(create_example_group("example_group"))
53 reporter.example_started("spec 3")
54 reporter.example_finished("spec 3")
55 reporter.dump
56 end
57
58 it "should handle multiple examples with the same name" do
59 error=RuntimeError.new
60 passing = ExampleGroup.new("example")
61 failing = ExampleGroup.new("example")
62
63 formatter.should_receive(:add_example_group).exactly(2).times
64 formatter.should_receive(:example_passed).with(passing).exactly(2).times
65 formatter.should_receive(:example_failed).with(failing, 1, failure)
66 formatter.should_receive(:example_failed).with(failing, 2, failure)
67 formatter.should_receive(:dump_failure).exactly(2).times
68 formatter.should_receive(:start_dump)
69 formatter.should_receive(:dump_pending)
70 formatter.should_receive(:close).with(no_args)
71 formatter.should_receive(:dump_summary).with(anything(), 4, 2, 0)
72 backtrace_tweaker.should_receive(:tweak_backtrace).twice
73
74 reporter.add_example_group(create_example_group("example_group"))
75 reporter.example_finished(passing)
76 reporter.example_finished(failing, error)
77
78 reporter.add_example_group(create_example_group("example_group"))
79 reporter.example_finished(passing)
80 reporter.example_finished(failing, error)
81 reporter.dump
82 end
83
84 it "should push stats to formatter even with no data" do
85 formatter.should_receive(:start_dump)
86 formatter.should_receive(:dump_pending)
87 formatter.should_receive(:dump_summary).with(anything(), 0, 0, 0)
88 formatter.should_receive(:close).with(no_args)
89 reporter.dump
90 end
91
92 it "should push time to formatter" do
93 formatter.should_receive(:start).with(5)
94 formatter.should_receive(:start_dump)
95 formatter.should_receive(:dump_pending)
96 formatter.should_receive(:close).with(no_args)
97 formatter.should_receive(:dump_summary) do |time, a, b|
98 time.to_s.should match(/[0-9].[0-9|e|-]+/)
99 end
100 reporter.start(5)
101 reporter.end
102 reporter.dump
103 end
104
105 describe Reporter, "reporting one passing example" do
106 it "should tell formatter example passed" do
107 formatter.should_receive(:example_passed)
108 reporter.example_finished("example")
109 end
110
111 it "should not delegate to backtrace tweaker" do
112 formatter.should_receive(:example_passed)
113 backtrace_tweaker.should_not_receive(:tweak_backtrace)
114 reporter.example_finished("example")
115 end
116
117 it "should account for passing example in stats" do
118 formatter.should_receive(:example_passed)
119 formatter.should_receive(:start_dump)
120 formatter.should_receive(:dump_pending)
121 formatter.should_receive(:dump_summary).with(anything(), 1, 0, 0)
122 formatter.should_receive(:close).with(no_args)
123 reporter.example_finished("example")
124 reporter.dump
125 end
126 end
127
128 describe Reporter, "reporting one failing example" do
129 it "should tell formatter that example failed" do
130 formatter.should_receive(:example_failed)
131 reporter.example_finished(example_group, 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(ExampleGroup.new("example"), RuntimeError.new)
138 end
139
140 it "should account for failing example in stats" do
141 example = ExampleGroup.new("example")
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.example_finished(example, RuntimeError.new)
149 reporter.dump
150 end
151
152 end
153
154 describe Reporter, "reporting one pending example (ExamplePendingError)" do
155 it "should tell formatter example is pending" do
156 example = ExampleGroup.new("example")
157 formatter.should_receive(:example_pending).with(example_group.description, example, "reason")
158 formatter.should_receive(:add_example_group).with(example_group)
159 reporter.add_example_group(example_group)
160 reporter.example_finished(example, Spec::Example::ExamplePendingError.new("reason"))
161 end
162
163 it "should account for pending example in stats" do
164 example = ExampleGroup.new("example")
165 formatter.should_receive(:example_pending).with(example_group.description, example, "reason")
166 formatter.should_receive(:start_dump)
167 formatter.should_receive(:dump_pending)
168 formatter.should_receive(:dump_summary).with(anything(), 1, 0, 1)
169 formatter.should_receive(:close).with(no_args)
170 formatter.should_receive(:add_example_group).with(example_group)
171 reporter.add_example_group(example_group)
172 reporter.example_finished(example, Spec::Example::ExamplePendingError.new("reason"))
173 reporter.dump
174 end
175 end
176
177 describe Reporter, "reporting one pending example (PendingExampleFixedError)" do
178 it "should tell formatter pending example is fixed" do
179 formatter.should_receive(:example_failed) do |name, counter, failure|
180 failure.header.should == "'example_group example' FIXED"
181 end
182 formatter.should_receive(:add_example_group).with(example_group)
183 reporter.add_example_group(example_group)
184 reporter.example_finished(ExampleGroup.new("example"), Spec::Example::PendingExampleFixedError.new("reason"))
185 end
186 end
187 end
188 end
189end