/
fuubar_spec.rb
152 lines (107 loc) · 3.42 KB
/
fuubar_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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
require 'spec_helper'
require 'stringio'
describe Fuubar do
let(:output) { StringIO.new }
let(:formatter) do
formatter = Fuubar.new(output)
formatter.start(2)
formatter
end
let(:progress_bar) { formatter.instance_variable_get(:@progress_bar) }
let(:example) { RSpec::Core::ExampleGroup.describe.example }
describe 'start' do
it 'should create a new ProgressBar' do
progress_bar.should be_instance_of ProgressBar::Base
end
it 'should set the format of the bar' do
progress_bar.instance_variable_get(:@format_string).should == ' %c/%C |%w>%i| %e '
end
it 'should set the total amount of specs' do
progress_bar.total.should == 2
end
it 'should set the output' do
progress_bar.send(:output).should == formatter.output
end
it 'should set the example_count' do
formatter.instance_variable_get(:@example_count).should == 2
end
it 'should set the bar mark to =' do
progress_bar.instance_variable_get(:@bar).progress_mark.should == '='
end
end
describe 'passed, pending and failed' do
before do
formatter.stub!(:increment)
end
describe 'example_passed' do
it 'should call the increment method' do
formatter.should_receive :increment
formatter.example_passed(example)
end
end
describe 'example_pending' do
it 'should call the increment method' do
formatter.should_receive :increment
formatter.example_pending(example)
end
it 'should set the state to :yellow' do
formatter.example_pending(example)
formatter.state.should == :yellow
end
it 'should not set the state to :yellow when it is :red already' do
formatter.instance_variable_set(:@state, :red)
formatter.example_pending(example)
formatter.state.should == :red
end
end
describe 'example_failed' do
before do
formatter.instafail.stub!(:example_failed)
end
it 'should call the increment method' do
formatter.should_receive :increment
formatter.example_failed(example)
end
it 'should call instafail.example_failed' do
formatter.instafail.should_receive(:example_failed).with(example)
formatter.example_failed(example)
end
it 'should set the state to :red' do
formatter.example_failed(example)
formatter.state.should == :red
end
end
end
describe 'increment' do
it 'should increment the progress bar' do
progress_bar.should_receive(:increment)
formatter.increment
end
pending 'should change the progress bar title' do
formatter.stub!(:finished_count).and_return(1)
formatter.stub!(:example_count).and_return(2)
formatter.increment
progress_bar.instance_variable_get(:@title).should == ' 1/2'
end
it 'should increment the progress bar before updating the title' do
progress_bar.should_receive(:increment)
formatter.increment
end
end
describe 'instafail' do
it 'should be an instance of RSpec::Instafail' do
formatter.instafail.should be_instance_of(RSpec::Instafail)
end
end
describe 'start_dump' do
it 'should finish the progress bar' do
progress_bar.should_receive(:finish)
formatter.start_dump
end
end
describe 'state' do
it 'should be :green by default' do
formatter.state.should == :green
end
end
end