|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | 3 | describe Script::Flag do |
4 | | - let(:options) { {"long" => "--help", "short" => "-h", "help" => "show this help"} } |
5 | | - subject { described_class.new options } |
| 4 | + let(:fixture) { :basic_flag } |
| 5 | + |
| 6 | + subject do |
| 7 | + options = load_fixture('script/flags')[fixture] |
| 8 | + described_class.new options |
| 9 | + end |
6 | 10 |
|
7 | 11 | describe '#aliases' do |
8 | 12 | context "with long and short options" do |
|
12 | 16 | end |
13 | 17 |
|
14 | 18 | context "with long option only" do |
15 | | - let(:options) { {"long" => "--long"} } |
| 19 | + let(:fixture) { :long_only } |
| 20 | + |
16 | 21 | it "returns an array with the long value" do |
17 | 22 | expect(subject.aliases).to eq ["--long"] |
18 | 23 | end |
19 | 24 | end |
20 | 25 |
|
21 | 26 | context "with short option only" do |
22 | | - let(:options) { {"short" => "-s"} } |
| 27 | + let(:fixture) { :short_only } |
| 28 | + |
23 | 29 | it "returns an array with the short value" do |
24 | 30 | expect(subject.aliases).to eq ["-s"] |
25 | 31 | end |
|
34 | 40 | end |
35 | 41 |
|
36 | 42 | context "with long option only" do |
37 | | - let(:options) { {"long" => "-l"} } |
| 43 | + let(:fixture) { :long_only } |
| 44 | + |
38 | 45 | it "returns the long option" do |
39 | | - expect(subject.name).to eq "-l" |
| 46 | + expect(subject.name).to eq "--long" |
40 | 47 | end |
41 | 48 | end |
42 | 49 |
|
43 | 50 | context "with short option only" do |
44 | | - let(:options) { {"short" => "-s"} } |
| 51 | + let(:fixture) { :short_only } |
| 52 | + |
45 | 53 | it "returns the short option" do |
46 | 54 | expect(subject.name).to eq "-s" |
47 | 55 | end |
|
61 | 69 | end |
62 | 70 |
|
63 | 71 | context "when the flag is required" do |
64 | | - let(:options) { {"long" => "--mandatory", "required" => true} } |
| 72 | + let(:fixture) { :required } |
| 73 | + |
65 | 74 | it "appends (required) to the usage string" do |
66 | 75 | expect(subject.usage_string extended: true).to eq "#{subject.usage_string} (required)" |
67 | 76 | end |
|
70 | 79 | end |
71 | 80 | end |
72 | 81 |
|
| 82 | + describe '#verify' do |
| 83 | + context "when the flag has no short or long" do |
| 84 | + let(:fixture) { :invalid_without_name } |
| 85 | + |
| 86 | + it "raises an error" do |
| 87 | + expect { subject.verify }.to raise_error(ConfigurationError, /must have a long and\/or short property/) |
| 88 | + end |
| 89 | + end |
| 90 | + end |
| 91 | + |
| 92 | + |
73 | 93 | end |
0 commit comments