|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Script::CatchAll do |
| 4 | + let(:fixture) { :basic_command } |
| 5 | + |
| 6 | + subject do |
| 7 | + options = load_fixture('script/commands')[fixture] |
| 8 | + Script::Command.new(options).catch_all |
| 9 | + end |
| 10 | + |
| 11 | + describe '#label' do |
| 12 | + context "when catch_all is disabled" do |
| 13 | + it "returns nil" do |
| 14 | + expect(subject.label).to be_nil |
| 15 | + end |
| 16 | + end |
| 17 | + |
| 18 | + context "when catch_all is a string" do |
| 19 | + let(:fixture) { :catch_all_string } |
| 20 | + |
| 21 | + it "returns an uppercase version of it" do |
| 22 | + expect(subject.label).to eq "EXTRA_PARAMS..." |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + context "when catch_all is set" do |
| 27 | + let(:fixture) { :catch_all_hash } |
| 28 | + |
| 29 | + it "returns an uppercase version of it" do |
| 30 | + expect(subject.label).to eq "ADDITIONAL_PARAMS..." |
| 31 | + end |
| 32 | + end |
| 33 | + |
| 34 | + context "in other cases" do |
| 35 | + let(:fixture) { :catch_all } |
| 36 | + |
| 37 | + it "returns '...'" do |
| 38 | + expect(subject.label).to eq "..." |
| 39 | + end |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + describe '#help' do |
| 44 | + context "when catch_all is disabled" do |
| 45 | + it "returns nil" do |
| 46 | + expect(subject.help).to be_nil |
| 47 | + end |
| 48 | + end |
| 49 | + |
| 50 | + context "when catch_all is a hash" do |
| 51 | + let(:fixture) { :catch_all_hash } |
| 52 | + |
| 53 | + it "returns an uppercase version of its label" do |
| 54 | + expect(subject.help).to eq "Any additional argument or flag" |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + context "in other cases" do |
| 59 | + let(:fixture) { :catch_all_string } |
| 60 | + |
| 61 | + it "returns nil" do |
| 62 | + expect(subject.help).to be_nil |
| 63 | + end |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | + describe '#required?' do |
| 68 | + context "when catch_all is disabled" do |
| 69 | + it "returns false" do |
| 70 | + expect(subject.required?).to be false |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + context "when catch_all['required'] is true" do |
| 75 | + let(:fixture) { :catch_all_hash } |
| 76 | + |
| 77 | + it "returns true" do |
| 78 | + expect(subject.required?).to be true |
| 79 | + end |
| 80 | + end |
| 81 | + |
| 82 | + context "in other cases" do |
| 83 | + let(:fixture) { :catch_all_string } |
| 84 | + |
| 85 | + it "returns false" do |
| 86 | + expect(subject.required?).to be false |
| 87 | + end |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + describe '#usage_string' do |
| 92 | + context "when catch_all is disabled" do |
| 93 | + it "returns nil" do |
| 94 | + expect(subject.usage_string).to be_nil |
| 95 | + end |
| 96 | + end |
| 97 | + |
| 98 | + context "when catch_all['required'] is true" do |
| 99 | + let(:fixture) { :catch_all_hash } |
| 100 | + |
| 101 | + it "returns a usage help without []" do |
| 102 | + expect(subject.usage_string).to eq "ADDITIONAL_PARAMS..." |
| 103 | + end |
| 104 | + end |
| 105 | + |
| 106 | + context "when catch_all['required'] is false" do |
| 107 | + let(:fixture) { :catch_all_string } |
| 108 | + |
| 109 | + it "returns a usage help with []" do |
| 110 | + expect(subject.usage_string).to eq "[EXTRA_PARAMS...]" |
| 111 | + end |
| 112 | + end |
| 113 | + |
| 114 | + context "when catch_all is true" do |
| 115 | + let(:fixture) { :catch_all } |
| 116 | + |
| 117 | + it "returns [...]" do |
| 118 | + expect(subject.usage_string).to eq "[...]" |
| 119 | + end |
| 120 | + end |
| 121 | + end |
| 122 | + |
| 123 | +end |
0 commit comments