forked from guard/guard
/
cli_spec.rb
278 lines (221 loc) · 7.23 KB
/
cli_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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
require 'spec_helper'
require 'guard/cli'
describe Guard::CLI do
let(:guard) { Guard }
let(:ui) { Guard::UI }
describe '#start' do
before { Guard.stub(:start) }
it 'delegates to Guard.start' do
guard.should_receive(:start)
subject.start
end
context 'with a Gemfile in the project dir' do
before do
File.stub(:exists?).with('Gemfile').and_return true
end
context 'when running with Bundler' do
before do
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = 'Gemfile'
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does not show the Bundler warning' do
ui.should_not_receive(:info).with(/Guard here!/)
subject.start
end
end
context 'when running without Bundler' do
before do
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = nil
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does show the Bundler warning' do
ui.should_receive(:info).with(/Guard here!/)
subject.start
end
it 'does not show the Bundler warning with the :no_bundler_warning flag' do
ui.should_not_receive(:info).with(/Guard here!/)
subject.options = { :no_bundler_warning => true }
subject.start
end
end
end
context 'without a Gemfile in the project dir' do
before do
File.should_receive(:exists?).with('Gemfile').and_return false
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = nil
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does not show the Bundler warning' do
ui.should_not_receive(:info).with(/Guard here!/)
subject.start
end
end
context 'with an interrupt signal' do
before do
guard.should_receive(:start).and_raise(Interrupt)
guard.stub(:stop)
end
it 'exits nicely' do
guard.should_receive(:stop)
subject.stub(:abort)
subject.start
end
it 'exits with failure status code' do
begin
subject.start
raise 'Guard did not abort!'
rescue SystemExit => e
e.status.should_not eq(0)
end
end
end
end
describe '#list' do
before { ::Guard::DslDescriber.stub(:list) }
it 'delegates to Guard::DslDescriber.list' do
::Guard::DslDescriber.should_receive(:list)
subject.list
end
context 'when running with Bundler' do
before do
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = 'Gemfile'
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does not show the Bundler warning' do
ui.should_not_receive(:info).with(/Guard here!/)
subject.list
end
end
context 'when running without Bundler' do
before do
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = nil
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does not show the Bundler warning' do
ui.should_receive(:info).with(/Guard here!/)
subject.list
end
end
end
describe '#version' do
it 'shows the current version' do
ui.should_not_receive(:info).with(/#{ ::Guard::VERSION }/)
subject.list
end
context 'when running with Bundler' do
before do
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = 'Gemfile'
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does not show the Bundler warning' do
ui.should_not_receive(:info).with(/Guard here!/)
subject.version
end
end
context 'when running without Bundler' do
before do
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = nil
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does not show the Bundler warning' do
ui.should_receive(:info).with(/Guard version/)
ui.should_receive(:info).with(/Guard here!/)
subject.version
end
end
end
describe '#init' do
let(:options) { { :bare => false } }
before do
subject.stub(:options => options)
Guard::Guardfile.stub(:create_guardfile)
Guard::Guardfile.stub(:initialize_all_templates)
end
it 'creates a Guardfile by delegating to Guardfile.create_guardfile' do
Guard::Guardfile.should_receive(:create_guardfile).with(:abort_on_existence => options[:bare])
subject.init
end
it 'initializes the templates of all installed Guards by delegating to Guardfile.initialize_all_templates' do
Guard::Guardfile.should_receive(:initialize_all_templates)
subject.init
end
it 'initializes each passed template by delegating to Guardfile.initialize_template' do
Guard::Guardfile.should_receive(:initialize_template).with('rspec')
Guard::Guardfile.should_receive(:initialize_template).with('pow')
subject.init 'rspec','pow'
end
context 'when passed a guard name' do
it 'initializes the template of the passed Guard by delegating to Guardfile.initialize_template' do
Guard::Guardfile.should_receive(:initialize_template).with('rspec')
subject.init 'rspec'
end
end
context 'with the bare option' do
let(:options) { {:bare => true} }
it 'Only creates the Guardfile and does not initialize any Guard template' do
Guard::Guardfile.should_receive(:create_guardfile)
Guard::Guardfile.should_not_receive(:initialize_template)
Guard::Guardfile.should_not_receive(:initialize_all_templates)
subject.init
end
end
context 'when running with Bundler' do
before do
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = 'Gemfile'
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does not show the Bundler warning' do
ui.should_not_receive(:info).with(/Guard here!/)
subject.init
end
end
context 'when running without Bundler' do
before do
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = nil
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does not show the Bundler warning' do
ui.should_receive(:info).with(/Guard here!/)
subject.init
end
end
end
describe '#show' do
before { ::Guard::DslDescriber.stub(:show) }
it 'delegates to Guard::DslDescriber.list' do
::Guard::DslDescriber.should_receive(:show)
subject.show
end
context 'when running with Bundler' do
before do
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = 'Gemfile'
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does not show the Bundler warning' do
ui.should_not_receive(:info).with(/Guard here!/)
subject.show
end
end
context 'when running without Bundler' do
before do
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = nil
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does not show the Bundler warning' do
ui.should_receive(:info).with(/Guard here!/)
subject.show
end
end
end
end