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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
require 'spec_helper'
require 'mspec/runner/mspec'
require 'mspec/commands/mspec-tag'
require 'mspec/runner/actions/tag'
require 'mspec/runner/actions/taglist'
require 'mspec/runner/actions/tagpurge'
one_spec = File.expand_path(File.dirname(__FILE__)) + '/fixtures/one_spec.rb'
two_spec = File.expand_path(File.dirname(__FILE__)) + '/fixtures/two_spec.rb'
describe MSpecTag, ".new" do
before :each do
@script = MSpecTag.new
end
it "sets config[:ltags] to an empty list" do
@script.config[:ltags].should == []
end
it "sets config[:tagger] to :add" do
@script.config[:tagger] = :add
end
it "sets config[:tag] to 'fails:'" do
@script.config[:tag] = 'fails:'
end
it "sets config[:outcome] to :fail" do
@script.config[:outcome] = :fail
end
end
describe MSpecTag, "#options" do
before :each do
@stdout, $stdout = $stdout, IOStub.new
@argv = [one_spec, two_spec]
@options, @config = new_option
MSpecOptions.stub(:new).and_return(@options)
@script = MSpecTag.new
@script.stub(:config).and_return(@config)
end
after :each do
$stdout = @stdout
end
it "enables the filter options" do
@options.should_receive(:filters)
@script.options @argv
end
it "enables the configure option" do
@options.should_receive(:configure)
@script.options @argv
end
it "provides a custom action (block) to the config option" do
@script.should_receive(:load).with("cfg.mspec")
@script.options ["-B", "cfg.mspec", one_spec]
end
it "enables the dry run option" do
@options.should_receive(:pretend)
@script.options @argv
end
it "enables the unguarded option" do
@options.should_receive(:unguarded)
@script.options @argv
end
it "enables the interrupt single specs option" do
@options.should_receive(:interrupt)
@script.options @argv
end
it "enables the formatter options" do
@options.should_receive(:formatters)
@script.options @argv
end
it "enables the verbose option" do
@options.should_receive(:verbose)
@script.options @argv
end
it "enables the version option" do
@options.should_receive(:version)
@script.options @argv
end
it "enables the help option" do
@options.should_receive(:help)
@script.options @argv
end
it "calls #custom_options" do
@script.should_receive(:custom_options).with(@options)
@script.options @argv
end
it "exits if there are no files to process" do
@options.should_receive(:parse).and_return([])
@script.should_receive(:exit)
@script.options
$stdout.should include "No files specified"
end
end
describe MSpecTag, "options" do
before :each do
@options, @config = new_option
MSpecOptions.stub(:new).and_return(@options)
@script = MSpecTag.new
@script.stub(:config).and_return(@config)
end
describe "-N, --add TAG" do
it "is enabled with #options" do
@options.stub(:on)
@options.should_receive(:on).with("-N", "--add", "TAG", an_instance_of(String))
@script.options [one_spec]
end
it "sets the mode to :add and sets the tag to TAG" do
["-N", "--add"].each do |opt|
@config[:tagger] = nil
@config[:tag] = nil
@script.options [opt, "taggit", one_spec]
@config[:tagger].should == :add
@config[:tag].should == "taggit:"
end
end
end
describe "-R, --del TAG" do
it "is enabled with #options" do
@options.stub(:on)
@options.should_receive(:on).with("-R", "--del", "TAG",
an_instance_of(String))
@script.options [one_spec]
end
it "it sets the mode to :del, the tag to TAG, and the outcome to :pass" do
["-R", "--del"].each do |opt|
@config[:tagger] = nil
@config[:tag] = nil
@config[:outcome] = nil
@script.options [opt, "taggit", one_spec]
@config[:tagger].should == :del
@config[:tag].should == "taggit:"
@config[:outcome].should == :pass
end
end
end
describe "-Q, --pass" do
it "is enabled with #options" do
@options.stub(:on)
@options.should_receive(:on).with("-Q", "--pass", an_instance_of(String))
@script.options [one_spec]
end
it "sets the outcome to :pass" do
["-Q", "--pass"].each do |opt|
@config[:outcome] = nil
@script.options [opt, one_spec]
@config[:outcome].should == :pass
end
end
end
describe "-F, --fail" do
it "is enabled with #options" do
@options.stub(:on)
@options.should_receive(:on).with("-F", "--fail", an_instance_of(String))
@script.options [one_spec]
end
it "sets the outcome to :fail" do
["-F", "--fail"].each do |opt|
@config[:outcome] = nil
@script.options [opt, one_spec]
@config[:outcome].should == :fail
end
end
end
describe "-L, --all" do
it "is enabled with #options" do
@options.stub(:on)
@options.should_receive(:on).with("-L", "--all", an_instance_of(String))
@script.options [one_spec]
end
it "sets the outcome to :all" do
["-L", "--all"].each do |opt|
@config[:outcome] = nil
@script.options [opt, one_spec]
@config[:outcome].should == :all
end
end
end
describe "--list TAG" do
it "is enabled with #options" do
@options.stub(:on)
@options.should_receive(:on).with("--list", "TAG", an_instance_of(String))
@script.options [one_spec]
end
it "sets the mode to :list" do
@config[:tagger] = nil
@script.options ["--list", "TAG", one_spec]
@config[:tagger].should == :list
end
it "sets ltags to include TAG" do
@config[:tag] = nil
@script.options ["--list", "TAG", one_spec]
@config[:ltags].should == ["TAG"]
end
end
describe "--list-all" do
it "is enabled with #options" do
@options.stub(:on)
@options.should_receive(:on).with("--list-all", an_instance_of(String))
@script.options [one_spec]
end
it "sets the mode to :list_all" do
@config[:tagger] = nil
@script.options ["--list-all", one_spec]
@config[:tagger].should == :list_all
end
end
describe "--purge" do
it "is enabled with #options" do
@options.stub(:on)
@options.should_receive(:on).with("--purge", an_instance_of(String))
@script.options [one_spec]
end
it "sets the mode to :purge" do
@config[:tagger] = nil
@script.options ["--purge", one_spec]
@config[:tagger].should == :purge
end
end
end
describe MSpecTag, "#run" do
before :each do
MSpec.stub(:process)
options = double("MSpecOptions").as_null_object
options.stub(:parse).and_return(["one", "two"])
MSpecOptions.stub(:new).and_return(options)
@config = { }
@script = MSpecTag.new
@script.stub(:exit)
@script.stub(:config).and_return(@config)
@script.stub(:files).and_return(["one", "two"])
@script.options
end
it "registers the tags patterns" do
@config[:tags_patterns] = [/spec/, "tags"]
MSpec.should_receive(:register_tags_patterns).with([/spec/, "tags"])
@script.run
end
it "registers the files to process" do
MSpec.should_receive(:register_files).with(["one", "two"])
@script.run
end
it "processes the files" do
MSpec.should_receive(:process)
@script.run
end
it "exits with the exit code registered with MSpec" do
MSpec.stub(:exit_code).and_return(7)
@script.should_receive(:exit).with(7)
@script.run
end
end
describe MSpecTag, "#register" do
before :each do
@script = MSpecTag.new
@config = @script.config
@config[:tag] = "fake:"
@config[:atags] = []
@config[:astrings] = []
@config[:ltags] = ["fails", "unstable"]
@script.stub(:files).and_return([])
@script.options "fake"
@t = double("TagAction")
@t.stub(:register)
@tl = double("TagListAction")
@tl.stub(:register)
end
it "raises an ArgumentError if no recognized action is given" do
@config[:tagger] = :totally_whack
lambda { @script.register }.should raise_error(ArgumentError)
end
describe "when config[:tagger] is the default (:add)" do
before :each do
@config[:formatter] = false
end
it "creates a TagAction" do
TagAction.should_receive(:new).and_return(@t)
@script.register
end
it "creates a TagAction if config[:tagger] is :del" do
@config[:tagger] = :del
@config[:outcome] = :pass
TagAction.should_receive(:new).with(:del, :pass, "fake", nil, [], []).and_return(@t)
@script.register
end
it "calls #register on the TagAction instance" do
TagAction.should_receive(:new).and_return(@t)
@t.should_receive(:register)
@script.register
end
end
describe "when config[:tagger] is :list" do
before :each do
TagListAction.should_receive(:new).with(@config[:ltags]).and_return(@tl)
@config[:tagger] = :list
end
it "creates a TagListAction" do
@tl.should_receive(:register)
@script.register
end
it "registers MSpec pretend mode" do
MSpec.should_receive(:register_mode).with(:pretend)
@script.register
end
it "sets config[:formatter] to false" do
@script.register
@config[:formatter].should be_false
end
end
describe "when config[:tagger] is :list_all" do
before :each do
TagListAction.should_receive(:new).with(nil).and_return(@tl)
@config[:tagger] = :list_all
end
it "creates a TagListAction" do
@tl.should_receive(:register)
@script.register
end
it "registers MSpec pretend mode" do
MSpec.should_receive(:register_mode).with(:pretend)
@script.register
end
it "sets config[:formatter] to false" do
@script.register
@config[:formatter].should be_false
end
end
describe "when config[:tagger] is :purge" do
before :each do
TagPurgeAction.should_receive(:new).and_return(@tl)
MSpec.stub(:register_mode)
@config[:tagger] = :purge
end
it "creates a TagPurgeAction" do
@tl.should_receive(:register)
@script.register
end
it "registers MSpec in pretend mode" do
MSpec.should_receive(:register_mode).with(:pretend)
@script.register
end
it "registers MSpec in unguarded mode" do
MSpec.should_receive(:register_mode).with(:unguarded)
@script.register
end
it "sets config[:formatter] to false" do
@script.register
@config[:formatter].should be_false
end
end
end
|