forked from rspec/rspec-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
base_text_formatter_spec.rb
130 lines (100 loc) · 3.86 KB
/
base_text_formatter_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
121
122
123
124
125
126
127
128
129
130
require "spec_helper"
module RSpec::Core::Formatters
describe BaseTextFormatter do
let(:output) { StringIO.new }
let(:formatter) { RSpec::Core::Formatters::BaseTextFormatter.new(output) }
describe "#summary_line" do
context "with 0s" do
it "outputs pluralized (excluding pending)" do
formatter.summary_line(0,0,0).should eq("0 examples, 0 failures")
end
end
context "with 1s" do
it "outputs singular (including pending)" do
formatter.summary_line(1,1,1).should eq("1 example, 1 failure, 1 pending")
end
end
context "with 2s" do
it "outputs pluralized (including pending)" do
formatter.summary_line(2,2,2).should eq("2 examples, 2 failures, 2 pending")
end
end
end
describe "#dump_failures" do
let(:group) { RSpec::Core::ExampleGroup.describe("group name") }
before { RSpec.configuration.stub(:color_enabled?) { false } }
def run_all_and_dump_failures
group.run_all(formatter)
formatter.dump_failures
end
it "preserves formatting" do
group.example("example name") { "this".should eq("that") }
run_all_and_dump_failures
output.string.should =~ /group name example name/m
output.string.should =~ /(\s+)expected \"that\"\n\1 got \"this\"/m
end
context 'for #share_examples_for' do
it 'outputs the name and location' do
share_examples_for 'foo bar' do
it("example name") { "this".should eq("that") }
end
line = __LINE__.next
group.it_should_behave_like('foo bar')
run_all_and_dump_failures
output.string.should include(
'Shared Example Group: "foo bar" called from ' +
"./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
)
end
context 'that contains nested example groups' do
it 'outputs the name and location' do
share_examples_for 'foo bar' do
describe 'nested group' do
it("example name") { "this".should eq("that") }
end
end
line = __LINE__.next
group.it_should_behave_like('foo bar')
run_all_and_dump_failures
output.string.should include(
'Shared Example Group: "foo bar" called from ' +
"./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
)
end
end
end
context 'for #share_as' do
it 'outputs the name and location' do
share_as :FooBar do
it("example name") { "this".should eq("that") }
end
line = __LINE__.next
group.send(:include, FooBar)
run_all_and_dump_failures
output.string.should include(
'Shared Example Group: "FooBar" called from ' +
"./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
)
end
context 'that contains nested example groups' do
it 'outputs the name and location' do
share_as :NestedFoo do
describe 'nested group' do
describe 'hell' do
it("example name") { "this".should eq("that") }
end
end
end
line = __LINE__.next
group.send(:include, NestedFoo)
run_all_and_dump_failures
output.string.should include(
'Shared Example Group: "NestedFoo" called from ' +
"./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
)
end
end
end
end
end
end