/
reporter_spec.rb
120 lines (98 loc) · 3.4 KB
/
reporter_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
require "spec_helper"
module RSpec::Core
describe Reporter do
describe "abort" do
let(:formatter) { double("formatter").as_null_object }
let(:example) { double("example") }
let(:reporter) { Reporter.new(formatter) }
%w[start_dump dump_pending dump_failures dump_summary close].each do |message|
it "sends #{message} to the formatter(s)" do
formatter.should_receive(message)
reporter.abort(nil)
end
end
end
context "given one formatter" do
it "passes messages to that formatter" do
formatter = double("formatter")
example = double("example")
reporter = Reporter.new(formatter)
formatter.should_receive(:example_started).
with(example)
reporter.example_started(example)
end
it "passes example_group_started and example_group_finished messages to that formatter in that order" do
order = []
formatter = double("formatter").as_null_object
formatter.stub(:example_group_started) { |group| order << "Started: #{group.description}" }
formatter.stub(:example_group_finished) { |group| order << "Finished: #{group.description}" }
group = ExampleGroup.describe("root")
group.describe("context 1") do
example("ignore") {}
end
group.describe("context 2") do
example("ignore") {}
end
group.run(Reporter.new(formatter))
expect(order).to eq([
"Started: root",
"Started: context 1",
"Finished: context 1",
"Started: context 2",
"Finished: context 2",
"Finished: root"
])
end
end
context "given an example group with no examples" do
it "does not pass example_group_started or example_group_finished to formatter" do
formatter = double("formatter").as_null_object
formatter.should_not_receive(:example_group_started)
formatter.should_not_receive(:example_group_finished)
group = ExampleGroup.describe("root")
group.run(Reporter.new(formatter))
end
end
context "given multiple formatters" do
it "passes messages to all formatters" do
formatters = [double("formatter"), double("formatter")]
example = double("example")
reporter = Reporter.new(*formatters)
formatters.each do |formatter|
formatter.
should_receive(:example_started).
with(example)
end
reporter.example_started(example)
end
end
describe "#report" do
it "supports one arg (count)" do
Reporter.new.report(1) {}
end
it "supports two args (count, seed)" do
Reporter.new.report(1, 2) {}
end
it "yields itself" do
reporter = Reporter.new
yielded = nil
reporter.report(3) {|r| yielded = r}
expect(yielded).to eq(reporter)
end
end
describe "timing" do
it "uses RSpec::Core::Time as to not be affected by changes to time in examples" do
formatter = double(:formatter).as_null_object
reporter = Reporter.new formatter
reporter.start 1
Time.stub(:now => Time.utc(2012, 10, 1))
duration = nil
formatter.stub(:dump_summary) do |dur, _, _, _|
duration = dur
end
reporter.finish 1234
expect(duration).to be < 0.2
end
end
end
end