@@ -4,8 +4,8 @@ class Application; end
4
4
module ApplicationHelper ; end
5
5
6
6
describe Thor ::Actions do
7
- def runner ( options = { } )
8
- @runner ||= MyCounter . new ( [ 1 ] , options , :destination_root => destination_root )
7
+ def runner ( options = { } , behavior = :invoke )
8
+ @runner ||= MyCounter . new ( [ 1 ] , options , :destination_root => destination_root , :behavior => behavior )
9
9
end
10
10
11
11
def action ( *args , &block )
@@ -280,28 +280,92 @@ def file
280
280
end
281
281
282
282
describe "#gsub_file" do
283
- it "replaces the content in the file" do
284
- action :gsub_file , "doc/README" , "__start__" , "START"
285
- expect ( File . binread ( file ) ) . to eq ( "START\n README\n __end__\n " )
286
- end
287
-
288
- it "does not replace if pretending" do
289
- runner ( :pretend => true )
290
- action :gsub_file , "doc/README" , "__start__" , "START"
291
- expect ( File . binread ( file ) ) . to eq ( "__start__\n README\n __end__\n " )
292
- end
293
-
294
- it "accepts a block" do
295
- action ( :gsub_file , "doc/README" , "__start__" ) { |match | match . gsub ( "__" , "" ) . upcase }
296
- expect ( File . binread ( file ) ) . to eq ( "START\n README\n __end__\n " )
297
- end
298
-
299
- it "logs status" do
300
- expect ( action ( :gsub_file , "doc/README" , "__start__" , "START" ) ) . to eq ( " gsub doc/README\n " )
301
- end
302
-
303
- it "does not log status if required" do
304
- expect ( action ( :gsub_file , file , "__" , :verbose => false ) { |match | match * 2 } ) . to be_empty
283
+ context "with invoke behavior" do
284
+ it "replaces the content in the file" do
285
+ action :gsub_file , "doc/README" , "__start__" , "START"
286
+ expect ( File . binread ( file ) ) . to eq ( "START\n README\n __end__\n " )
287
+ end
288
+
289
+ it "does not replace if pretending" do
290
+ runner ( :pretend => true )
291
+ action :gsub_file , "doc/README" , "__start__" , "START"
292
+ expect ( File . binread ( file ) ) . to eq ( "__start__\n README\n __end__\n " )
293
+ end
294
+
295
+ it "accepts a block" do
296
+ action ( :gsub_file , "doc/README" , "__start__" ) { |match | match . gsub ( "__" , "" ) . upcase }
297
+ expect ( File . binread ( file ) ) . to eq ( "START\n README\n __end__\n " )
298
+ end
299
+
300
+ it "logs status" do
301
+ expect ( action ( :gsub_file , "doc/README" , "__start__" , "START" ) ) . to eq ( " gsub doc/README\n " )
302
+ end
303
+
304
+ it "does not log status if required" do
305
+ expect ( action ( :gsub_file , file , "__" , :verbose => false ) { |match | match * 2 } ) . to be_empty
306
+ end
307
+ end
308
+
309
+ context "with revoke behavior" do
310
+ context "and no force option" do
311
+ it "does not replace the content in the file" do
312
+ runner ( { } , :revoke )
313
+ action :gsub_file , "doc/README" , "__start__" , "START"
314
+ expect ( File . binread ( file ) ) . to eq ( "__start__\n README\n __end__\n " )
315
+ end
316
+
317
+ it "does not replace if pretending" do
318
+ runner ( { :pretend => true } , :revoke )
319
+ action :gsub_file , "doc/README" , "__start__" , "START"
320
+ expect ( File . binread ( file ) ) . to eq ( "__start__\n README\n __end__\n " )
321
+ end
322
+
323
+ it "does not replace the content in the file when given a block" do
324
+ runner ( { } , :revoke )
325
+ action ( :gsub_file , "doc/README" , "__start__" ) { |match | match . gsub ( "__" , "" ) . upcase }
326
+ expect ( File . binread ( file ) ) . to eq ( "__start__\n README\n __end__\n " )
327
+ end
328
+
329
+ it "does not log status" do
330
+ runner ( { } , :revoke )
331
+ expect ( action ( :gsub_file , "doc/README" , "__start__" , "START" ) ) . to be_empty
332
+ end
333
+
334
+ it "does not log status if required" do
335
+ runner ( { } , :revoke )
336
+ expect ( action ( :gsub_file , file , "__" , :verbose => false ) { |match | match * 2 } ) . to be_empty
337
+ end
338
+ end
339
+
340
+ context "and force option" do
341
+ it "replaces the content in the file" do
342
+ runner ( { } , :revoke )
343
+ action :gsub_file , "doc/README" , "__start__" , "START" , :force => true
344
+ expect ( File . binread ( file ) ) . to eq ( "START\n README\n __end__\n " )
345
+ end
346
+
347
+ it "does not replace if pretending" do
348
+ runner ( { :pretend => true } , :revoke )
349
+ action :gsub_file , "doc/README" , "__start__" , "START" , :force => true
350
+ expect ( File . binread ( file ) ) . to eq ( "__start__\n README\n __end__\n " )
351
+ end
352
+
353
+ it "replaces the content in the file when given a block" do
354
+ runner ( { } , :revoke )
355
+ action ( :gsub_file , "doc/README" , "__start__" , :force => true ) { |match | match . gsub ( "__" , "" ) . upcase }
356
+ expect ( File . binread ( file ) ) . to eq ( "START\n README\n __end__\n " )
357
+ end
358
+
359
+ it "logs status" do
360
+ runner ( { } , :revoke )
361
+ expect ( action ( :gsub_file , "doc/README" , "__start__" , "START" , :force => true ) ) . to eq ( " gsub doc/README\n " )
362
+ end
363
+
364
+ it "does not log status if required" do
365
+ runner ( { } , :revoke )
366
+ expect ( action ( :gsub_file , file , "__" , :verbose => false , :force => true ) { |match | match * 2 } ) . to be_empty
367
+ end
368
+ end
305
369
end
306
370
end
307
371
0 commit comments