|
405 | 405 | end |
406 | 406 | end |
407 | 407 |
|
408 | | - describe '#public_commands' do |
409 | | - let(:fixture) { :private_commands } |
| 408 | + describe '#mode' do |
| 409 | + context 'when flags and commands are defined' do |
| 410 | + let(:fixture) { :mode_global_flags } |
410 | 411 |
|
411 | | - it 'returns an array of Command objects excluding private commands' do |
412 | | - expect(subject.public_commands.count).to eq 1 |
413 | | - expect(subject.public_commands.first.name).to eq 'connect' |
| 412 | + it 'returns :global_flags' do |
| 413 | + expect(subject.mode).to eq :global_flags |
| 414 | + end |
414 | 415 | end |
415 | | - end |
416 | 416 |
|
417 | | - describe '#public_commands_aliases' do |
418 | | - let(:fixture) { :private_commands } |
| 417 | + context 'when only commands are defined' do |
| 418 | + let(:fixture) { :mode_commands } |
419 | 419 |
|
420 | | - it 'returns an array of command aliases of public subcommands' do |
421 | | - expect(subject.public_command_aliases).to eq %w[connect c] |
| 420 | + it 'returns :commands' do |
| 421 | + expect(subject.mode).to eq :commands |
| 422 | + end |
422 | 423 | end |
423 | | - end |
424 | 424 |
|
425 | | - describe '#user_file_path' do |
426 | | - it 'returns the path to the user file' do |
427 | | - expect(subject.user_file_path 'test.sh').to eq 'spec/tmp/src/test.sh' |
428 | | - end |
| 425 | + context 'when args and flags are defined' do |
| 426 | + let(:fixture) { :mode_args_and_flags } |
429 | 427 |
|
430 | | - context 'when the file argument does not end with .sh extension' do |
431 | | - it 'returns the path with .sh appended' do |
432 | | - expect(subject.user_file_path 'test').to eq 'spec/tmp/src/test.sh' |
| 428 | + it 'returns :args_and_flags' do |
| 429 | + expect(subject.mode).to eq :args_and_flags |
433 | 430 | end |
434 | 431 | end |
435 | 432 |
|
436 | | - context 'when partials_extension is set and the argument does not end with the selected extension' do |
437 | | - before { Settings.partials_extension = 'bash' } |
438 | | - after { Settings.partials_extension = 'sh' } |
| 433 | + context 'when only args are defined' do |
| 434 | + let(:fixture) { :mode_args } |
439 | 435 |
|
440 | | - it 'returns the path with the selected extension appended' do |
441 | | - expect(subject.user_file_path 'test').to eq 'spec/tmp/src/test.bash' |
| 436 | + it 'returns :args' do |
| 437 | + expect(subject.mode).to eq :args |
442 | 438 | end |
443 | 439 | end |
444 | | - end |
445 | 440 |
|
446 | | - describe '#user_file_exist?' do |
447 | | - before { FileUtils.mkdir_p 'spec/tmp/src' } |
448 | | - |
449 | | - context 'when the file exists in the user source path' do |
450 | | - before { FileUtils.touch 'spec/tmp/src/test.sh' } |
| 441 | + context 'when only flags are defined' do |
| 442 | + let(:fixture) { :mode_flags } |
451 | 443 |
|
452 | | - it 'returns true' do |
453 | | - expect(subject.user_file_exist?('test')).to be true |
| 444 | + it 'returns :flags' do |
| 445 | + expect(subject.mode).to eq :flags |
454 | 446 | end |
455 | 447 | end |
456 | 448 |
|
457 | | - context 'when the file does not in the user source path' do |
458 | | - before { FileUtils.rm_f 'spec/tmp/src/test.sh' } |
| 449 | + context 'when nothing is defined' do |
| 450 | + let(:fixture) { :mode_empty } |
459 | 451 |
|
460 | | - it 'returns false' do |
461 | | - expect(subject.user_file_exist?('test')).to be false |
| 452 | + it 'returns :empty' do |
| 453 | + expect(subject.mode).to eq :empty |
462 | 454 | end |
463 | 455 | end |
464 | 456 | end |
465 | 457 |
|
| 458 | + describe '#public_commands' do |
| 459 | + let(:fixture) { :private_commands } |
| 460 | + |
| 461 | + it 'returns an array of Command objects excluding private commands' do |
| 462 | + expect(subject.public_commands.count).to eq 1 |
| 463 | + expect(subject.public_commands.first.name).to eq 'connect' |
| 464 | + end |
| 465 | + end |
| 466 | + |
| 467 | + describe '#public_commands_aliases' do |
| 468 | + let(:fixture) { :private_commands } |
| 469 | + |
| 470 | + it 'returns an array of command aliases of public subcommands' do |
| 471 | + expect(subject.public_command_aliases).to eq %w[connect c] |
| 472 | + end |
| 473 | + end |
| 474 | + |
466 | 475 | describe '#required_args' do |
467 | 476 | it 'returns an array of only the required Argument objects' do |
468 | 477 | expect(subject.required_args.size).to eq 1 |
|
546 | 555 | end |
547 | 556 | end |
548 | 557 |
|
549 | | - describe '#mode' do |
550 | | - context 'when flags and commands are defined' do |
551 | | - let(:fixture) { :mode_global_flags } |
552 | | - |
553 | | - it 'returns :global_flags' do |
554 | | - expect(subject.mode).to eq :global_flags |
555 | | - end |
556 | | - end |
557 | | - |
558 | | - context 'when only commands are defined' do |
559 | | - let(:fixture) { :mode_commands } |
560 | | - |
561 | | - it 'returns :commands' do |
562 | | - expect(subject.mode).to eq :commands |
563 | | - end |
564 | | - end |
565 | | - |
566 | | - context 'when args and flags are defined' do |
567 | | - let(:fixture) { :mode_args_and_flags } |
568 | | - |
569 | | - it 'returns :args_and_flags' do |
570 | | - expect(subject.mode).to eq :args_and_flags |
571 | | - end |
572 | | - end |
573 | | - |
574 | | - context 'when only args are defined' do |
575 | | - let(:fixture) { :mode_args } |
576 | | - |
577 | | - it 'returns :args' do |
578 | | - expect(subject.mode).to eq :args |
579 | | - end |
580 | | - end |
581 | | - |
582 | | - context 'when only flags are defined' do |
583 | | - let(:fixture) { :mode_flags } |
584 | | - |
585 | | - it 'returns :flags' do |
586 | | - expect(subject.mode).to eq :flags |
587 | | - end |
588 | | - end |
589 | | - |
590 | | - context 'when nothing is defined' do |
591 | | - let(:fixture) { :mode_empty } |
592 | | - |
593 | | - it 'returns :empty' do |
594 | | - expect(subject.mode).to eq :empty |
595 | | - end |
596 | | - end |
597 | | - end |
598 | | - |
599 | 558 | describe '#usage_string' do |
600 | 559 | context 'when flags and commands are defined' do |
601 | 560 | let(:fixture) { :mode_global_flags } |
|
660 | 619 | end |
661 | 620 | end |
662 | 621 | end |
| 622 | + |
| 623 | + context 'when the command is set as default' do |
| 624 | + let(:fixture) { :default_command } |
| 625 | + |
| 626 | + it 'returns the correct string' do |
| 627 | + expect(subject.default_command.usage_string).to eq 'cli [get]' |
| 628 | + end |
| 629 | + end |
| 630 | + |
| 631 | + end |
| 632 | + |
| 633 | + describe '#user_file_path' do |
| 634 | + it 'returns the path to the user file' do |
| 635 | + expect(subject.user_file_path 'test.sh').to eq 'spec/tmp/src/test.sh' |
| 636 | + end |
| 637 | + |
| 638 | + context 'when the file argument does not end with .sh extension' do |
| 639 | + it 'returns the path with .sh appended' do |
| 640 | + expect(subject.user_file_path 'test').to eq 'spec/tmp/src/test.sh' |
| 641 | + end |
| 642 | + end |
| 643 | + |
| 644 | + context 'when partials_extension is set and the argument does not end with the selected extension' do |
| 645 | + before { Settings.partials_extension = 'bash' } |
| 646 | + after { Settings.partials_extension = 'sh' } |
| 647 | + |
| 648 | + it 'returns the path with the selected extension appended' do |
| 649 | + expect(subject.user_file_path 'test').to eq 'spec/tmp/src/test.bash' |
| 650 | + end |
| 651 | + end |
| 652 | + end |
| 653 | + |
| 654 | + describe '#user_file_exist?' do |
| 655 | + before { FileUtils.mkdir_p 'spec/tmp/src' } |
| 656 | + |
| 657 | + context 'when the file exists in the user source path' do |
| 658 | + before { FileUtils.touch 'spec/tmp/src/test.sh' } |
| 659 | + |
| 660 | + it 'returns true' do |
| 661 | + expect(subject.user_file_exist?('test')).to be true |
| 662 | + end |
| 663 | + end |
| 664 | + |
| 665 | + context 'when the file does not in the user source path' do |
| 666 | + before { FileUtils.rm_f 'spec/tmp/src/test.sh' } |
| 667 | + |
| 668 | + it 'returns false' do |
| 669 | + expect(subject.user_file_exist?('test')).to be false |
| 670 | + end |
| 671 | + end |
663 | 672 | end |
664 | 673 |
|
665 | 674 | describe '#whitelisted_args' do |
|
0 commit comments