cuprum-cli 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -0
  3. data/README.md +10 -0
  4. data/lib/cuprum/cli/argument.rb +2 -2
  5. data/lib/cuprum/cli/command.rb +2 -4
  6. data/lib/cuprum/cli/commands/ci/rspec_each_command.rb +34 -8
  7. data/lib/cuprum/cli/commands/ci.rb +8 -0
  8. data/lib/cuprum/cli/commands/file/new_command.rb +42 -49
  9. data/lib/cuprum/cli/commands/file.rb +8 -5
  10. data/lib/cuprum/cli/dependencies/clock/mock.rb +28 -0
  11. data/lib/cuprum/cli/dependencies/clock.rb +29 -0
  12. data/lib/cuprum/cli/dependencies/file_system/mock.rb +150 -18
  13. data/lib/cuprum/cli/dependencies/file_system.rb +145 -10
  14. data/lib/cuprum/cli/dependencies.rb +2 -0
  15. data/lib/cuprum/cli/errors.rb +0 -1
  16. data/lib/cuprum/cli/{commands/file/generate_file.rb → files/create_file.rb} +6 -48
  17. data/lib/cuprum/cli/{commands/file → files/engines}/render_erb.rb +6 -6
  18. data/lib/cuprum/cli/files/engines.rb +76 -0
  19. data/lib/cuprum/cli/{errors/files → files/errors}/file_not_writeable.rb +3 -3
  20. data/lib/cuprum/cli/files/errors/generator_error.rb +46 -0
  21. data/lib/cuprum/cli/{errors/files → files/errors}/missing_parameter.rb +5 -5
  22. data/lib/cuprum/cli/{errors/files → files/errors}/missing_template.rb +3 -3
  23. data/lib/cuprum/cli/{errors/files → files/errors}/template_error.rb +3 -3
  24. data/lib/cuprum/cli/files/errors.rb +19 -0
  25. data/lib/cuprum/cli/files/generator.rb +431 -0
  26. data/lib/cuprum/cli/files/generators/basic_generator.rb +15 -0
  27. data/lib/cuprum/cli/files/generators/rspec_generator.rb +19 -0
  28. data/lib/cuprum/cli/files/generators/ruby_generator.rb +32 -0
  29. data/lib/cuprum/cli/files/generators.rb +25 -0
  30. data/lib/cuprum/cli/files/template.rb +62 -0
  31. data/lib/cuprum/cli/files/templates/basic_template.rb +39 -0
  32. data/lib/cuprum/cli/files/templates/file_template.rb +60 -0
  33. data/lib/cuprum/cli/files/templates/string_template.rb +29 -0
  34. data/lib/cuprum/cli/files/templates.rb +59 -0
  35. data/lib/cuprum/cli/files.rb +18 -0
  36. data/lib/cuprum/cli/integrations/async/commands/rspec_each_command.rb +32 -0
  37. data/lib/cuprum/cli/integrations/async/commands.rb +11 -0
  38. data/lib/cuprum/cli/integrations/async.rb +21 -0
  39. data/lib/cuprum/cli/integrations/thor/registry.rb +7 -29
  40. data/lib/cuprum/cli/integrations/thor/task.rb +37 -7
  41. data/lib/cuprum/cli/metadata.rb +54 -5
  42. data/lib/cuprum/cli/option.rb +10 -4
  43. data/lib/cuprum/cli/options/class_methods.rb +19 -1
  44. data/lib/cuprum/cli/registry.rb +131 -55
  45. data/lib/cuprum/cli/rspec/deferred/dependencies/file_system_examples.rb +1303 -1001
  46. data/lib/cuprum/cli/rspec/deferred/generators_examples.rb +112 -0
  47. data/lib/cuprum/cli/rspec/deferred/metadata_examples.rb +300 -0
  48. data/lib/cuprum/cli/rspec/deferred/options_examples.rb +8 -2
  49. data/lib/cuprum/cli/rspec/deferred/registry_examples.rb +343 -108
  50. data/lib/cuprum/cli/rspec/deferred/templates_examples.rb +183 -0
  51. data/lib/cuprum/cli/version.rb +1 -1
  52. data/lib/cuprum/cli.rb +1 -0
  53. metadata +31 -14
  54. data/lib/cuprum/cli/commands/file/resolve_template.rb +0 -136
  55. data/lib/cuprum/cli/commands/file/templates.rb +0 -71
  56. data/lib/cuprum/cli/errors/files/template_not_resolved.rb +0 -54
  57. data/lib/cuprum/cli/errors/files.rb +0 -19
  58. /data/lib/cuprum/cli/{commands/file → files}/templates/rspec.rb.erb +0 -0
  59. /data/lib/cuprum/cli/{commands/file → files}/templates/ruby.rb.erb +0 -0
@@ -96,60 +96,76 @@ module Cuprum::Cli::RSpec::Deferred
96
96
  it { expect(subject.commands).to be_frozen }
97
97
 
98
98
  wrap_deferred 'when the registry has many commands' do
99
- it { expect(subject.commands).to be == commands }
99
+ it { expect(subject.commands).to eq(commands) }
100
100
  end
101
101
  end
102
102
 
103
103
  describe '#register' do
104
- deferred_examples 'should configure the command' do
104
+ deferred_examples 'should register command' do |command_class, **config|
105
105
  context 'when the command is registered' do
106
+ let(:expected_command) do
107
+ expected = command_class
108
+ expected = instance_exec(&expected) if expected.is_a?(Proc)
109
+ expected = Object.const_get(expected) if expected.is_a?(String)
110
+
111
+ expected
112
+ end
106
113
  let(:expected_arguments) do
107
114
  config.fetch(:arguments, [])
108
115
  end
109
116
  let(:expected_description) do
110
- config.fetch(:description, command.description)
117
+ config
118
+ .fetch(:description, expected_command.description)
119
+ .then do |value|
120
+ value.is_a?(Proc) ? instance_exec(&value) : value
121
+ end
111
122
  end
112
123
  let(:expected_full_description) do
113
- config.fetch(:full_description) do
114
- config.fetch(:description, command.full_description)
115
- end
124
+ config
125
+ .fetch(:full_description) do
126
+ config.fetch(:description, expected_command.full_description)
127
+ end # rubocop:disable Style/MultilineBlockChain
128
+ .then do |value|
129
+ value.is_a?(Proc) ? instance_exec(&value) : value
130
+ end
116
131
  end
117
132
  let(:expected_full_name) do
118
- config.fetch(:full_name, command.full_name)
133
+ config.fetch(:full_name, expected_command.full_name)
119
134
  end
120
135
  let(:expected_options) do
121
136
  config.fetch(:options, {})
122
137
  end
138
+ let(:registered) do
139
+ registry.commands[expected_full_name]
140
+ end
123
141
 
124
- before(:example) { registry.register(command, **config) }
142
+ before(:example) { register_commands }
125
143
 
126
- it { expect(registered).to be_a(Class).and(be < command) }
144
+ it { expect(registered).to be_a(Class).and(be <= expected_command) }
127
145
 
128
- it 'should configure the command argument values' do
129
- expect(registered.argument_values).to be == expected_arguments
146
+ it 'should configure the command arguments' do
147
+ expect(registered.argument_values).to eq(expected_arguments)
130
148
  end
131
149
 
132
150
  it 'should configure the command description' do
133
- expect(registered.description).to be == expected_description
151
+ expect(registered.description).to eq(expected_description)
134
152
  end
135
153
 
136
154
  it 'should configure the command full description' do
137
155
  expect(registered.full_description)
138
- .to be == expected_full_description
156
+ .to eq(expected_full_description)
139
157
  end
140
158
 
141
159
  it 'should configure the command full name' do
142
- expect(registered.full_name).to be == expected_full_name
160
+ expect(registered.full_name).to eq(expected_full_name)
143
161
  end
144
162
 
145
- it 'should configure the command option values' do
146
- expect(registered.option_values).to be == expected_options
163
+ it 'should configure the command options' do
164
+ expect(registered.option_values).to eq(expected_options)
147
165
  end
148
166
  end
149
167
  end
150
168
 
151
- let(:command) { Spec::CustomCommand }
152
- let(:config) { {} }
153
169
  let(:expected_keywords) do
154
170
  %i[
155
171
  arguments
@@ -159,10 +175,12 @@ module Cuprum::Cli::RSpec::Deferred
159
175
  options
160
176
  ]
161
177
  end
162
- let(:registered) do
163
- name = config.fetch(:full_name, command.full_name)
178
+ let(:commands) { [Spec::CustomCommand] }
179
+ let(:config) { {} }
180
+ let(:block) { nil }
164
181
 
165
- registry.commands[name]
182
+ define_method :register_commands do
183
+ registry.register(*commands, **config, &block)
166
184
  end
167
185
 
168
186
  example_class 'Spec::CustomCommand', Cuprum::Cli::Command do |klass|
@@ -173,7 +191,9 @@ module Cuprum::Cli::RSpec::Deferred
173
191
  expect(subject)
174
192
  .to respond_to(:register)
175
193
  .with(1).argument
194
+ .and_unlimited_arguments
176
195
  .and_keywords(*expected_keywords)
196
+ .and_a_block
177
197
  end
178
198
 
179
199
  it 'should alias the method as #add' do
@@ -182,6 +202,18 @@ module Cuprum::Cli::RSpec::Deferred
182
202
  .as(:add)
183
203
  end
184
204
 
205
+ describe 'with no commands' do
206
+ let(:commands) { [] }
207
+ let(:error_message) do
208
+ tools.assertions.error_message_for('presence', as: 'commands')
209
+ end
210
+
211
+ it 'should raise an exception' do
212
+ expect { register_commands }
213
+ .to raise_error ArgumentError, error_message
214
+ end
215
+ end
216
+
185
217
  describe 'with command: nil' do
186
218
  let(:error_message) do
187
219
  tools.assertions.error_message_for('class', as: 'command')
@@ -220,50 +252,55 @@ module Cuprum::Cli::RSpec::Deferred
220
252
  end
221
253
 
222
254
  describe 'with full_name: an Object' do
255
+ let(:config) { super().merge(full_name: Object.new.freeze) }
223
256
  let(:error_message) do
224
257
  tools.assertions.error_message_for('name', as: 'full_name')
225
258
  end
226
259
 
227
260
  it 'should raise an exception' do
228
- expect { subject.register(command, full_name: Object.new.freeze) }
261
+ expect { register_commands }
229
262
  .to raise_error ArgumentError, error_message
230
263
  end
231
264
  end
232
265
 
233
266
  describe 'with full_name: an empty String' do
267
+ let(:config) { super().merge(full_name: '') }
234
268
  let(:error_message) do
235
269
  tools.assertions.error_message_for('presence', as: 'full_name')
236
270
  end
237
271
 
238
272
  it 'should raise an exception' do
239
- expect { subject.register(command, full_name: '') }
273
+ expect { register_commands }
240
274
  .to raise_error ArgumentError, error_message
241
275
  end
242
276
  end
243
277
 
244
278
  describe 'with full_name: an invalid String' do
279
+ let(:config) { super().merge(full_name: 'UPPER_CASE') }
245
280
  let(:error_message) do
246
281
  'full_name does not match format category:sub_category:do_something'
247
282
  end
248
283
 
249
284
  it 'should raise an exception' do
250
- expect { subject.register(command, full_name: 'UPPER_CASE') }
285
+ expect { register_commands }
251
286
  .to raise_error ArgumentError, error_message
252
287
  end
253
288
  end
254
289
 
255
290
  describe 'with command: an anonymous command class' do
256
- let(:command) do
257
- Class.new(Cuprum::Cli::Command) do
258
- description 'An anonymous command.'
259
- end
291
+ let(:commands) do
292
+ [
293
+ Class.new(Cuprum::Cli::Command) do
294
+ description 'An anonymous command.'
295
+ end
296
+ ]
260
297
  end
261
298
  let(:error_message) do
262
299
  tools.assertions.error_message_for('presence', as: 'full_name')
263
300
  end
264
301
 
265
302
  it 'should raise an exception' do
266
- expect { subject.register(command) }
303
+ expect { register_commands }
267
304
  .to raise_error ArgumentError, error_message
268
305
  end
269
306
 
@@ -271,13 +308,11 @@ module Cuprum::Cli::RSpec::Deferred
271
308
  let(:full_name) { 'custom:scoped:command' }
272
309
  let(:config) { super().merge(full_name:) }
273
310
 
274
- it 'should register the command' do
275
- expect { subject.register(command, full_name:) }
276
- .to change(registry, :commands)
277
- .to have_key(full_name)
278
- end
311
+ it { expect(register_commands).to be registry }
279
312
 
280
- include_deferred 'should configure the command'
313
+ include_deferred 'should register command',
314
+ -> { commands.first },
315
+ full_name: 'custom:scoped:command'
281
316
 
282
317
  context 'when the registry already defines the command' do
283
318
  let(:other_command) do
@@ -295,7 +330,7 @@ module Cuprum::Cli::RSpec::Deferred
295
330
  end
296
331
 
297
332
  it 'should raise an exception' do
298
- expect { subject.register(command, full_name:) }
333
+ expect { register_commands }
299
334
  .to raise_error NameError, error_message
300
335
  end
301
336
  end
@@ -303,15 +338,11 @@ module Cuprum::Cli::RSpec::Deferred
303
338
  end
304
339
 
305
340
  describe 'with command: a command class' do
306
- it { expect(subject.register(command)).to be registry }
341
+ let(:commands) { [Spec::CustomCommand] }
307
342
 
308
- it 'should register the command', :aggregate_failures do
309
- expect { subject.register(command) }
310
- .to change(registry, :commands)
311
- .to have_key(command.full_name)
343
+ it { expect(register_commands).to be registry }
312
344
 
313
- expect(registry.commands[command.full_name]).to be command
314
- end
345
+ include_deferred 'should register command', 'Spec::CustomCommand'
315
346
 
316
347
  context 'when the registry already defines the command' do
317
348
  let(:other_command) do
@@ -320,31 +351,62 @@ module Cuprum::Cli::RSpec::Deferred
320
351
  end
321
352
  end
322
353
  let(:error_message) do
323
- "command already registered as #{command.full_name} - " \
354
+ "command already registered as #{commands.first.full_name} - " \
324
355
  'Cuprum::Cli::Command'
325
356
  end
326
357
 
327
358
  before(:example) do
328
- subject.register(other_command, full_name: command.full_name)
359
+ subject.register(other_command, full_name: 'spec:custom')
329
360
  end
330
361
 
331
362
  it 'should raise an exception' do
332
- expect { subject.register(command) }
363
+ expect { register_commands }
333
364
  .to raise_error NameError, error_message
334
365
  end
335
366
  end
336
367
 
368
+ describe 'with arguments: value' do
369
+ let(:arguments) { %w[ichi ni san] }
370
+ let(:config) { super().merge(arguments:) }
371
+
372
+ it { expect(register_commands).to be registry }
373
+
374
+ include_deferred 'should register command',
375
+ 'Spec::CustomCommand',
376
+ arguments: %w[ichi ni san]
377
+ end
378
+
379
+ describe 'with description: value' do
380
+ let(:description) { 'No one is quite sure what this does.' }
381
+ let(:config) { super().merge(description:) }
382
+
383
+ include_deferred 'should register command',
384
+ 'Spec::CustomCommand',
385
+ description: -> { description }
386
+ end
387
+
388
+ describe 'with full_description: value' do
389
+ let(:full_description) do
390
+ <<~DESC
391
+ No one is quite sure what this does.
392
+
393
+ ...but it sure looks cool!
394
+ DESC
395
+ end
396
+ let(:config) { super().merge(full_description:) }
397
+
398
+ include_deferred 'should register command',
399
+ 'Spec::CustomCommand',
400
+ full_description: -> { full_description }
401
+ end
402
+
337
403
  describe 'with full_name: value' do
338
404
  let(:full_name) { 'custom:scoped:command' }
339
405
  let(:config) { super().merge(full_name:) }
340
406
 
341
- it 'should register the command' do
342
- expect { subject.register(command, full_name:) }
343
- .to change(registry, :commands)
344
- .to have_key(full_name)
345
- end
346
-
347
- include_deferred 'should configure the command'
407
+ include_deferred 'should register command',
408
+ 'Spec::CustomCommand',
409
+ full_name: 'custom:scoped:command'
348
410
 
349
411
  context 'when the registry already defines the command' do
350
412
  let(:other_command) do
@@ -362,88 +424,261 @@ module Cuprum::Cli::RSpec::Deferred
362
424
  end
363
425
 
364
426
  it 'should raise an exception' do
365
- expect { subject.register(command, full_name:) }
427
+ expect { register_commands }
366
428
  .to raise_error NameError, error_message
367
429
  end
368
430
  end
369
431
  end
370
- end
371
-
372
- describe 'with arguments: value' do
373
- let(:arguments) { %w[ichi ni san] }
374
- let(:config) { super().merge(arguments:) }
375
432
 
376
- it { expect(subject.register(command)).to be registry }
433
+ describe 'with options: value' do
434
+ let(:options) { { option: 'value', other: 'other' } }
435
+ let(:config) { super().merge(options:) }
377
436
 
378
- it 'should register the command' do
379
- expect { subject.register(command, arguments:) }
380
- .to change(registry, :commands)
381
- .to have_key(command.full_name)
437
+ include_deferred 'should register command',
438
+ 'Spec::CustomCommand',
439
+ options: { option: 'value', other: 'other' }
382
440
  end
383
441
 
384
- include_deferred 'should configure the command'
385
- end
442
+ describe 'with multiple config options' do
443
+ let(:arguments) { %w[ichi ni san] }
444
+ let(:description) { 'No one is quite sure what this does.' }
445
+ let(:options) { { option: 'value', other: 'other' } }
446
+ let(:config) do
447
+ super().merge(arguments:, description:, options:)
448
+ end
449
+
450
+ include_deferred 'should register command',
451
+ 'Spec::CustomCommand',
452
+ arguments: %w[ichi ni san],
453
+ description: -> { description },
454
+ options: { option: 'value', other: 'other' }
455
+ end
386
456
 
387
- describe 'with description: value' do
388
- let(:description) { 'No one is quite sure what this does.' }
389
- let(:config) { super().merge(description:) }
457
+ describe 'with a block that configures the command' do
458
+ let(:block) do
459
+ lambda do |command|
460
+ command.with_full_name 'spec:example_command'
461
+ end
462
+ end
390
463
 
391
- it 'should register the command' do
392
- expect { subject.register(command, description:) }
393
- .to change(registry, :commands)
394
- .to have_key(command.full_name)
464
+ include_deferred 'should register command',
465
+ 'Spec::CustomCommand',
466
+ full_name: 'spec:example_command'
395
467
  end
396
468
 
397
- include_deferred 'should configure the command'
398
- end
469
+ describe 'with a block that filters the command' do
470
+ let(:block) do
471
+ ->(_command) {}
472
+ end
399
473
 
400
- describe 'with full_description: value' do
401
- let(:full_description) do
402
- <<~DESC
403
- No one is quite sure what this does.
474
+ it { expect(register_commands).to be registry }
404
475
 
405
- ...but it sure looks cool!
406
- DESC
476
+ it 'should not register a command' do
477
+ expect { register_commands }.not_to change(registry, :commands)
478
+ end
407
479
  end
408
- let(:config) { super().merge(full_description:) }
480
+ end
409
481
 
410
- it 'should register the command' do
411
- expect { subject.register(command, full_description:) }
412
- .to change(registry, :commands)
413
- .to have_key(command.full_name)
482
+ describe 'with multiple command classes' do
483
+ let(:commands) do
484
+ [
485
+ Class
486
+ .new(Spec::CustomCommand)
487
+ .with_full_name('spec:example:command_one'),
488
+ Class
489
+ .new(Spec::CustomCommand)
490
+ .with_full_name('spec:example:command_two'),
491
+ Class
492
+ .new(Spec::CustomCommand)
493
+ .with_full_name('spec:example:command_three')
494
+ ]
414
495
  end
415
496
 
416
- include_deferred 'should configure the command'
417
- end
497
+ it { expect(register_commands).to be registry }
498
+
499
+ include_deferred 'should register command',
500
+ 'Spec::CustomCommand',
501
+ full_name: 'spec:example:command_one'
502
+
503
+ include_deferred 'should register command',
504
+ 'Spec::CustomCommand',
505
+ full_name: 'spec:example:command_two'
506
+
507
+ include_deferred 'should register command',
508
+ 'Spec::CustomCommand',
509
+ full_name: 'spec:example:command_three'
418
510
 
419
- describe 'with options: value' do
420
- let(:options) { { option: 'value', other: 'other' } }
421
- let(:config) { super().merge(options:) }
511
+ describe 'with configuration options' do
512
+ let(:config) { super().merge(options: { key: 'value' }) }
422
513
 
423
- it 'should register the command' do
424
- expect { subject.register(command, options:) }
425
- .to change(registry, :commands)
426
- .to have_key(command.full_name)
514
+ include_deferred 'should register command',
515
+ 'Spec::CustomCommand',
516
+ full_name: 'spec:example:command_one',
517
+ options: { key: 'value' }
518
+
519
+ include_deferred 'should register command',
520
+ 'Spec::CustomCommand',
521
+ full_name: 'spec:example:command_two',
522
+ options: { key: 'value' }
523
+
524
+ include_deferred 'should register command',
525
+ 'Spec::CustomCommand',
526
+ full_name: 'spec:example:command_three',
527
+ options: { key: 'value' }
427
528
  end
428
529
 
429
- include_deferred 'should configure the command'
430
- end
530
+ describe 'with a block that configures the commands' do
531
+ let(:block) do
532
+ lambda do |command|
533
+ name = command.full_name.sub('example', 'custom')
534
+
535
+ command.with_full_name(name)
536
+ end
537
+ end
538
+
539
+ it { expect(register_commands).to be registry }
540
+
541
+ include_deferred 'should register command',
542
+ 'Spec::CustomCommand',
543
+ full_name: 'spec:custom:command_one'
431
544
 
432
- describe 'with multiple config options' do
433
- let(:arguments) { %w[ichi ni san] }
434
- let(:description) { 'No one is quite sure what this does.' }
435
- let(:options) { { option: 'value', other: 'other' } }
436
- let(:config) do
437
- super().merge(arguments:, description:, options:)
545
+ include_deferred 'should register command',
546
+ 'Spec::CustomCommand',
547
+ full_name: 'spec:custom:command_two'
548
+
549
+ include_deferred 'should register command',
550
+ 'Spec::CustomCommand',
551
+ full_name: 'spec:custom:command_three'
438
552
  end
439
553
 
440
- it 'should register the command' do
441
- expect { subject.register(command, **config) }
442
- .to change(registry, :commands)
443
- .to have_key(command.full_name)
554
+ describe 'with a block that filters the commands' do
555
+ let(:block) do
556
+ lambda do |command|
557
+ next if command.full_name.include?('two')
558
+
559
+ command
560
+ end
561
+ end
562
+
563
+ it { expect(register_commands).to be registry }
564
+
565
+ it 'should not register filtered commands' do
566
+ register_commands
567
+
568
+ expect(registry.commands)
569
+ .not_to have_key('spec:example:command_two')
570
+ end
571
+
572
+ include_deferred 'should register command',
573
+ 'Spec::CustomCommand',
574
+ full_name: 'spec:example:command_one'
575
+
576
+ include_deferred 'should register command',
577
+ 'Spec::CustomCommand',
578
+ full_name: 'spec:example:command_three'
579
+ end
580
+ end
581
+
582
+ describe 'with an Array of command classes' do
583
+ let(:commands) do
584
+ [
585
+ Class
586
+ .new(Spec::CustomCommand)
587
+ .with_full_name('spec:example:command_one'),
588
+ [
589
+ Class
590
+ .new(Spec::CustomCommand)
591
+ .with_full_name('spec:example:command_two'),
592
+ Class
593
+ .new(Spec::CustomCommand)
594
+ .with_full_name('spec:example:command_three')
595
+ ]
596
+ ]
597
+ end
598
+
599
+ it { expect(register_commands).to be registry }
600
+
601
+ include_deferred 'should register command',
602
+ 'Spec::CustomCommand',
603
+ full_name: 'spec:example:command_one'
604
+
605
+ include_deferred 'should register command',
606
+ 'Spec::CustomCommand',
607
+ full_name: 'spec:example:command_two'
608
+
609
+ include_deferred 'should register command',
610
+ 'Spec::CustomCommand',
611
+ full_name: 'spec:example:command_three'
612
+
613
+ describe 'with configuration options' do
614
+ let(:config) { super().merge(options: { key: 'value' }) }
615
+
616
+ include_deferred 'should register command',
617
+ 'Spec::CustomCommand',
618
+ full_name: 'spec:example:command_one',
619
+ options: { key: 'value' }
620
+
621
+ include_deferred 'should register command',
622
+ 'Spec::CustomCommand',
623
+ full_name: 'spec:example:command_two',
624
+ options: { key: 'value' }
625
+
626
+ include_deferred 'should register command',
627
+ 'Spec::CustomCommand',
628
+ full_name: 'spec:example:command_three',
629
+ options: { key: 'value' }
630
+ end
631
+
632
+ describe 'with a block that configures the commands' do
633
+ let(:block) do
634
+ lambda do |command|
635
+ name = command.full_name.sub('example', 'custom')
636
+
637
+ command.with_full_name(name)
638
+ end
639
+ end
640
+
641
+ it { expect(register_commands).to be registry }
642
+
643
+ include_deferred 'should register command',
644
+ 'Spec::CustomCommand',
645
+ full_name: 'spec:custom:command_one'
646
+
647
+ include_deferred 'should register command',
648
+ 'Spec::CustomCommand',
649
+ full_name: 'spec:custom:command_two'
650
+
651
+ include_deferred 'should register command',
652
+ 'Spec::CustomCommand',
653
+ full_name: 'spec:custom:command_three'
444
654
  end
445
655
 
446
- include_deferred 'should configure the command'
656
+ describe 'with a block that filters the commands' do
657
+ let(:block) do
658
+ lambda do |command|
659
+ next if command.full_name.include?('two')
660
+
661
+ command
662
+ end
663
+ end
664
+
665
+ it { expect(register_commands).to be registry }
666
+
667
+ it 'should not register filtered commands' do
668
+ register_commands
669
+
670
+ expect(registry.commands)
671
+ .not_to have_key('spec:example:command_two')
672
+ end
673
+
674
+ include_deferred 'should register command',
675
+ 'Spec::CustomCommand',
676
+ full_name: 'spec:example:command_one'
677
+
678
+ include_deferred 'should register command',
679
+ 'Spec::CustomCommand',
680
+ full_name: 'spec:example:command_three'
681
+ end
447
682
  end
448
683
  end
449
684
  end