command_kit 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +6 -0
- data/README.md +3 -0
- data/command_kit.gemspec +7 -2
- data/lib/command_kit/completion/install.rb +276 -0
- data/lib/command_kit/env/prefix.rb +41 -0
- data/lib/command_kit/env/shell.rb +58 -0
- data/lib/command_kit/version.rb +1 -1
- metadata +4 -64
- data/spec/arguments/argument_spec.rb +0 -133
- data/spec/arguments/argument_value_spec.rb +0 -66
- data/spec/arguments_spec.rb +0 -279
- data/spec/bug_report_spec.rb +0 -266
- data/spec/colors_spec.rb +0 -771
- data/spec/command_kit_spec.rb +0 -8
- data/spec/command_name_spec.rb +0 -130
- data/spec/command_spec.rb +0 -123
- data/spec/commands/auto_load/subcommand_spec.rb +0 -82
- data/spec/commands/auto_load_spec.rb +0 -159
- data/spec/commands/auto_require_spec.rb +0 -142
- data/spec/commands/fixtures/test_auto_load/cli/commands/test1.rb +0 -10
- data/spec/commands/fixtures/test_auto_load/cli/commands/test2.rb +0 -10
- data/spec/commands/fixtures/test_auto_require/lib/test_auto_require/cli/commands/test1.rb +0 -10
- data/spec/commands/help_spec.rb +0 -66
- data/spec/commands/parent_command_spec.rb +0 -40
- data/spec/commands/subcommand_spec.rb +0 -99
- data/spec/commands_spec.rb +0 -865
- data/spec/description_spec.rb +0 -179
- data/spec/edit_spec.rb +0 -72
- data/spec/env/home_spec.rb +0 -46
- data/spec/env/path_spec.rb +0 -84
- data/spec/env_spec.rb +0 -123
- data/spec/examples_spec.rb +0 -211
- data/spec/exception_handler_spec.rb +0 -103
- data/spec/file_utils_spec.rb +0 -59
- data/spec/fixtures/template.erb +0 -5
- data/spec/help/man_spec.rb +0 -345
- data/spec/help_spec.rb +0 -94
- data/spec/inflector_spec.rb +0 -166
- data/spec/interactive_spec.rb +0 -415
- data/spec/main_spec.rb +0 -179
- data/spec/man_spec.rb +0 -46
- data/spec/open_app_spec.rb +0 -85
- data/spec/options/option_spec.rb +0 -343
- data/spec/options/option_value_spec.rb +0 -171
- data/spec/options/parser_spec.rb +0 -274
- data/spec/options/quiet_spec.rb +0 -51
- data/spec/options/verbose_spec.rb +0 -51
- data/spec/options/version_spec.rb +0 -146
- data/spec/options_spec.rb +0 -465
- data/spec/os/linux_spec.rb +0 -164
- data/spec/os_spec.rb +0 -233
- data/spec/package_manager_spec.rb +0 -806
- data/spec/pager_spec.rb +0 -217
- data/spec/printing/fields_spec.rb +0 -167
- data/spec/printing/indent_spec.rb +0 -132
- data/spec/printing/lists_spec.rb +0 -99
- data/spec/printing/tables/border_style.rb +0 -43
- data/spec/printing/tables/cell_builer_spec.rb +0 -135
- data/spec/printing/tables/row_builder_spec.rb +0 -165
- data/spec/printing/tables/style_spec.rb +0 -377
- data/spec/printing/tables/table_builder_spec.rb +0 -252
- data/spec/printing/tables/table_formatter_spec.rb +0 -1190
- data/spec/printing/tables_spec.rb +0 -1069
- data/spec/printing_spec.rb +0 -106
- data/spec/program_name_spec.rb +0 -70
- data/spec/spec_helper.rb +0 -3
- data/spec/stdio_spec.rb +0 -264
- data/spec/sudo_spec.rb +0 -51
- data/spec/terminal_spec.rb +0 -231
- data/spec/usage_spec.rb +0 -237
- data/spec/xdg_spec.rb +0 -191
data/spec/main_spec.rb
DELETED
@@ -1,179 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'command_kit/main'
|
3
|
-
|
4
|
-
describe CommandKit::Main do
|
5
|
-
module TestMain
|
6
|
-
class TestCommand
|
7
|
-
include CommandKit::Main
|
8
|
-
end
|
9
|
-
|
10
|
-
class TestCommandWithInitialize
|
11
|
-
include CommandKit::Main
|
12
|
-
|
13
|
-
attr_reader :foo
|
14
|
-
|
15
|
-
attr_reader :bar
|
16
|
-
|
17
|
-
def initialize(foo: 'foo', bar: 'bar', **kwargs)
|
18
|
-
super(**kwargs)
|
19
|
-
|
20
|
-
@foo = foo
|
21
|
-
@bar = bar
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
let(:command_class) { TestMain::TestCommand }
|
27
|
-
|
28
|
-
describe ".start" do
|
29
|
-
subject { command_class }
|
30
|
-
|
31
|
-
it "must exit with 0 by default" do
|
32
|
-
expect(subject).to receive(:exit).with(0)
|
33
|
-
|
34
|
-
subject.start
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when given an argv argument" do
|
38
|
-
let(:argv) { %w[one two three] }
|
39
|
-
|
40
|
-
it "must pass argv to .main" do
|
41
|
-
expect(subject).to receive(:main).with(argv)
|
42
|
-
allow(subject).to receive(:exit)
|
43
|
-
|
44
|
-
subject.start(argv)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "when given keyword arguments" do
|
49
|
-
let(:command_class) { TestMain::TestCommandWithInitialize }
|
50
|
-
|
51
|
-
let(:kwargs) { {foo: 'custom foo', bar: 'custom bar'} }
|
52
|
-
|
53
|
-
it "must pass the keyword arguments down to .main" do
|
54
|
-
expect(subject).to receive(:main).with(ARGV, **kwargs)
|
55
|
-
allow(subject).to receive(:exit)
|
56
|
-
|
57
|
-
subject.start(**kwargs)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "when Interrupt is raised" do
|
62
|
-
module TestMain
|
63
|
-
class TestCommandWithInterrupt
|
64
|
-
include CommandKit::Main
|
65
|
-
|
66
|
-
def main(*argv)
|
67
|
-
raise(Interrupt)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
let(:command_class) { TestMain::TestCommandWithInterrupt }
|
73
|
-
|
74
|
-
it "must exit with 130" do
|
75
|
-
expect(command_class).to receive(:exit).with(130)
|
76
|
-
|
77
|
-
command_class.start
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "when Errno::EPIPE is raised" do
|
82
|
-
module TestMain
|
83
|
-
class TestCommandWithBrokenPipe
|
84
|
-
include CommandKit::Main
|
85
|
-
|
86
|
-
def main(*argv)
|
87
|
-
raise(Errno::EPIPE)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
let(:command_class) { TestMain::TestCommandWithBrokenPipe }
|
93
|
-
|
94
|
-
it "must exit with 0" do
|
95
|
-
expect(command_class).to receive(:exit).with(0)
|
96
|
-
|
97
|
-
command_class.start
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
module TestMain
|
103
|
-
class TestCommandWithSystemExit
|
104
|
-
|
105
|
-
include CommandKit::Main
|
106
|
-
|
107
|
-
def run(*argv)
|
108
|
-
raise(SystemExit.new(-1))
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe ".main" do
|
115
|
-
subject { command_class }
|
116
|
-
|
117
|
-
it "must return 0 by default" do
|
118
|
-
expect(subject.main).to eq(0)
|
119
|
-
end
|
120
|
-
|
121
|
-
let(:command_class) { TestMain::TestCommandWithInitialize }
|
122
|
-
|
123
|
-
context "when given a custom argv" do
|
124
|
-
let(:instance) { command_class.new }
|
125
|
-
let(:argv) { %w[one two three] }
|
126
|
-
|
127
|
-
it "must call #main with the custom argv" do
|
128
|
-
expect(subject).to receive(:new).with(no_args).and_return(instance)
|
129
|
-
expect(instance).to receive(:main).with(argv)
|
130
|
-
|
131
|
-
subject.main(argv)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context "when given keyword arguments" do
|
136
|
-
let(:kwargs) { {foo: 'custom foo', bar: 'custom bar'} }
|
137
|
-
let(:instance) { command_class.new(**kwargs) }
|
138
|
-
|
139
|
-
it "must pass the keyword arguments .new then call #main" do
|
140
|
-
expect(subject).to receive(:new).with(**kwargs).and_return(instance)
|
141
|
-
expect(instance).to receive(:main).with([])
|
142
|
-
|
143
|
-
subject.main(**kwargs)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
context "when #main raises SystemExit" do
|
148
|
-
let(:command_class) { TestMain::TestCommandWithSystemExit }
|
149
|
-
|
150
|
-
it "must rescue SystemExit and return the exit status code" do
|
151
|
-
expect(subject.main()).to eq(-1)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
describe "#main" do
|
157
|
-
subject { command_class.new }
|
158
|
-
|
159
|
-
it "must return 0 by default" do
|
160
|
-
expect(subject.main).to eq(0)
|
161
|
-
end
|
162
|
-
|
163
|
-
it "must call #run with the given argv" do
|
164
|
-
argv = ["foo", "bar", "baz"]
|
165
|
-
|
166
|
-
expect(subject).to receive(:run).with(*argv)
|
167
|
-
|
168
|
-
subject.main(argv)
|
169
|
-
end
|
170
|
-
|
171
|
-
context "when #run raises SystemExit" do
|
172
|
-
let(:command_class) { TestMain::TestCommandWithSystemExit }
|
173
|
-
|
174
|
-
it "must rescue SystemExit and return the exit status code" do
|
175
|
-
expect(subject.main()).to eq(-1)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
data/spec/man_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'command_kit/man'
|
3
|
-
|
4
|
-
describe CommandKit::Man do
|
5
|
-
module TestMan
|
6
|
-
class TestCommand
|
7
|
-
include CommandKit::Man
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:command_class) { TestMan::TestCommand }
|
12
|
-
|
13
|
-
subject { command_class.new }
|
14
|
-
|
15
|
-
describe "#man" do
|
16
|
-
let(:man_page) { 'foo' }
|
17
|
-
|
18
|
-
it "must call system() with the given man page" do
|
19
|
-
expect(subject).to receive(:system).with('man',man_page)
|
20
|
-
|
21
|
-
subject.man(man_page)
|
22
|
-
end
|
23
|
-
|
24
|
-
context "when given a non-String man-page argument" do
|
25
|
-
let(:man_page_arg) { double(:non_string_arg) }
|
26
|
-
|
27
|
-
it "must call #to_s on the man-page argument" do
|
28
|
-
expect(man_page_arg).to receive(:to_s).and_return(man_page)
|
29
|
-
|
30
|
-
expect(subject).to receive(:system).with('man',man_page)
|
31
|
-
|
32
|
-
subject.man(man_page_arg)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "when given the section: keyword argument" do
|
37
|
-
let(:section) { 7 }
|
38
|
-
|
39
|
-
it "must call system() with the given section number and man page" do
|
40
|
-
expect(subject).to receive(:system).with('man',section.to_s,man_page)
|
41
|
-
|
42
|
-
subject.man(man_page, section: section)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/spec/open_app_spec.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'command_kit/open_app'
|
3
|
-
|
4
|
-
describe CommandKit::OpenApp do
|
5
|
-
module TestOpenApp
|
6
|
-
class TestCommand
|
7
|
-
include CommandKit::OpenApp
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:command_class) { TestOpenApp::TestCommand }
|
12
|
-
|
13
|
-
subject { command_class.new }
|
14
|
-
|
15
|
-
describe "#initialize" do
|
16
|
-
context "when the OS is macOS" do
|
17
|
-
subject { command_class.new(os: :macos) }
|
18
|
-
|
19
|
-
it "must set @open_command to \"open\"" do
|
20
|
-
expect(subject.instance_variable_get("@open_command")).to eq("open")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "when the OS is Linux" do
|
25
|
-
subject { command_class.new(os: :linux) }
|
26
|
-
|
27
|
-
it "must set @open_command to \"xdg-open\"" do
|
28
|
-
expect(subject.instance_variable_get("@open_command")).to eq("xdg-open")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "when the OS is FreeBSD" do
|
33
|
-
subject { command_class.new(os: :freebsd) }
|
34
|
-
|
35
|
-
it "must set @open_command to \"xdg-open\"" do
|
36
|
-
expect(subject.instance_variable_get("@open_command")).to eq("xdg-open")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "when the OS is OpenBSD" do
|
41
|
-
subject { command_class.new(os: :openbsd) }
|
42
|
-
|
43
|
-
it "must set @open_command to \"xdg-open\"" do
|
44
|
-
expect(subject.instance_variable_get("@open_command")).to eq("xdg-open")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "when the OS is NetBSD" do
|
49
|
-
subject { command_class.new(os: :openbsd) }
|
50
|
-
|
51
|
-
it "must set @open_command to \"xdg-open\"" do
|
52
|
-
expect(subject.instance_variable_get("@open_command")).to eq("xdg-open")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "when the OS is Windows" do
|
57
|
-
subject { command_class.new(os: :windows) }
|
58
|
-
|
59
|
-
it "must set @open_command to \"start\"" do
|
60
|
-
expect(subject.instance_variable_get("@open_command")).to eq("start")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "#open_app_for" do
|
66
|
-
context "when @open_command is set" do
|
67
|
-
let(:file_or_uri) { "foo" }
|
68
|
-
let(:status) { true }
|
69
|
-
|
70
|
-
it "must execute the @open_command with the given URI or file" do
|
71
|
-
expect(subject).to receive(:system).with(subject.instance_variable_get("@open_command"),file_or_uri).and_return(status)
|
72
|
-
|
73
|
-
expect(subject.open_app_for(file_or_uri)).to be(status)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when @open_command is not set" do
|
78
|
-
before do
|
79
|
-
subject.instance_variable_set("@open_command",nil)
|
80
|
-
end
|
81
|
-
|
82
|
-
it { expect(subject.open_app_for("foo")).to be(nil) }
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
data/spec/options/option_spec.rb
DELETED
@@ -1,343 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'command_kit/options/option'
|
3
|
-
|
4
|
-
describe CommandKit::Options::Option do
|
5
|
-
let(:name) { :foo }
|
6
|
-
let(:short) { nil }
|
7
|
-
let(:long) { '--foo' }
|
8
|
-
let(:equals) { false }
|
9
|
-
let(:value_usage) { 'FOO' }
|
10
|
-
let(:value_required) { true }
|
11
|
-
let(:value) do
|
12
|
-
{
|
13
|
-
usage: value_usage,
|
14
|
-
required: value_required
|
15
|
-
}
|
16
|
-
end
|
17
|
-
let(:desc) { 'Foo option' }
|
18
|
-
let(:block) do
|
19
|
-
->(arg) { @foo = arg }
|
20
|
-
end
|
21
|
-
|
22
|
-
subject do
|
23
|
-
described_class.new(name, short: short,
|
24
|
-
long: long,
|
25
|
-
equals: equals,
|
26
|
-
desc: desc,
|
27
|
-
value: value,
|
28
|
-
&block)
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#initialize" do
|
32
|
-
context "when the short: keyword is given" do
|
33
|
-
subject { described_class.new(name, short: short, desc: desc) }
|
34
|
-
|
35
|
-
it "must set #short" do
|
36
|
-
expect(subject.short).to eq(short)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "when the short: keyword is not given" do
|
41
|
-
subject { described_class.new(name, desc: desc) }
|
42
|
-
|
43
|
-
it { expect(subject.short).to be(nil) }
|
44
|
-
end
|
45
|
-
|
46
|
-
context "when the long: keyword is given" do
|
47
|
-
let(:long) { '--opt' }
|
48
|
-
|
49
|
-
subject { described_class.new(name, long: long, desc: desc) }
|
50
|
-
|
51
|
-
it "must set #long" do
|
52
|
-
expect(subject.long).to eq(long)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "when the long: keyword is not given" do
|
57
|
-
subject { described_class.new(name, desc: desc) }
|
58
|
-
|
59
|
-
it "default #long to a '--option' flag based on #name" do
|
60
|
-
expect(subject.long).to eq("--#{name}")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context "when the equals: keyword is given" do
|
65
|
-
let(:equals) { true }
|
66
|
-
|
67
|
-
subject { described_class.new(name, equals: equals, desc: desc) }
|
68
|
-
|
69
|
-
it "must set #equals" do
|
70
|
-
expect(subject.equals?).to eq(equals)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context "when the equals: keyword is not given" do
|
75
|
-
subject { described_class.new(name, desc: desc) }
|
76
|
-
|
77
|
-
it { expect(subject.equals?).to be(false) }
|
78
|
-
end
|
79
|
-
|
80
|
-
context "when the values: keyword is given" do
|
81
|
-
context "and it is a Hash" do
|
82
|
-
let(:type) { Integer }
|
83
|
-
|
84
|
-
subject { described_class.new(name, value: {type: type}, desc: desc) }
|
85
|
-
|
86
|
-
it "must initialize #value" do
|
87
|
-
expect(subject.value).to be_kind_of(CommandKit::Options::OptionValue)
|
88
|
-
expect(subject.value.type).to eq(type)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context "and it is true" do
|
93
|
-
subject { described_class.new(name, value: true, desc: desc) }
|
94
|
-
|
95
|
-
it "must initialize #value with defaults" do
|
96
|
-
expect(subject.value).to be_kind_of(CommandKit::Options::OptionValue)
|
97
|
-
expect(subject.value.type).to eq(String)
|
98
|
-
expect(subject.value.required?).to be(true)
|
99
|
-
expect(subject.value.usage).to eq('STR')
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context "and it is false" do
|
104
|
-
subject { described_class.new(name, value: false, desc: desc) }
|
105
|
-
|
106
|
-
it "must not initialize #value" do
|
107
|
-
expect(subject.value).to be(nil)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "and it is nil" do
|
112
|
-
subject { described_class.new(name, value: nil, desc: desc) }
|
113
|
-
|
114
|
-
it "must not initialize #value" do
|
115
|
-
expect(subject.value).to be(nil)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context "when it is another type" do
|
120
|
-
it do
|
121
|
-
expect {
|
122
|
-
described_class.new(name, value: 'foo', desc: desc)
|
123
|
-
}.to raise_error(TypeError)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
context "when the values: keyword is not given" do
|
129
|
-
subject { described_class.new(name, desc: desc) }
|
130
|
-
|
131
|
-
it { expect(subject.value).to be(nil) }
|
132
|
-
end
|
133
|
-
|
134
|
-
context "when the desc: keyword is given" do
|
135
|
-
subject { described_class.new(name, desc: desc) }
|
136
|
-
|
137
|
-
it "must set #desc" do
|
138
|
-
expect(subject.desc).to eq(desc)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
context "when the desc: keyword is not given" do
|
143
|
-
it do
|
144
|
-
expect {
|
145
|
-
described_class.new(name)
|
146
|
-
}.to raise_error(ArgumentError)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
it "must default #category to nil" do
|
151
|
-
expect(subject.category).to be(nil)
|
152
|
-
end
|
153
|
-
|
154
|
-
context "when the category: keyword is given" do
|
155
|
-
let(:category) { 'Other Options' }
|
156
|
-
|
157
|
-
subject { described_class.new(name, desc: desc, category: category) }
|
158
|
-
|
159
|
-
it "must set #category" do
|
160
|
-
expect(subject.category).to eq(category)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
context "when a block is given" do
|
165
|
-
subject { described_class.new(name, desc: desc, &block) }
|
166
|
-
|
167
|
-
it "must set #block" do
|
168
|
-
expect(subject.block).to eq(block)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
context "when no block is given" do
|
173
|
-
subject { described_class.new(name, desc: desc) }
|
174
|
-
|
175
|
-
it { expect(subject.block).to be(nil) }
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
describe "#equals?" do
|
180
|
-
context "when initialized with equals: true" do
|
181
|
-
let(:equals) { true }
|
182
|
-
|
183
|
-
it { expect(subject.equals?).to be(true) }
|
184
|
-
end
|
185
|
-
|
186
|
-
context "when initialized with equals: false" do
|
187
|
-
let(:equals) { false }
|
188
|
-
|
189
|
-
it { expect(subject.equals?).to be(false) }
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
describe "#separator" do
|
194
|
-
context "when #value is initialized" do
|
195
|
-
context "and #equals? is true" do
|
196
|
-
let(:equals) { true }
|
197
|
-
|
198
|
-
it { expect(subject.separator).to eq('=') }
|
199
|
-
end
|
200
|
-
|
201
|
-
context "and #equals? is false" do
|
202
|
-
let(:equals) { false }
|
203
|
-
|
204
|
-
it { expect(subject.separator).to eq(' ') }
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
context "when #value is not initialized" do
|
209
|
-
let(:value) { nil }
|
210
|
-
|
211
|
-
it { expect(subject.separator).to be(nil) }
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
describe "#usage" do
|
216
|
-
let(:long) { '--foo' }
|
217
|
-
|
218
|
-
it "must start with the long '--option'" do
|
219
|
-
expect(subject.usage.last).to start_with(long)
|
220
|
-
end
|
221
|
-
|
222
|
-
context "when #value is initialized" do
|
223
|
-
it "must return '--option USAGE'" do
|
224
|
-
expect(subject.usage.last).to eq("#{long} #{subject.value.usage}")
|
225
|
-
end
|
226
|
-
|
227
|
-
context "and #equals? is true" do
|
228
|
-
let(:equals) { true }
|
229
|
-
|
230
|
-
it "must return '--option=USAGE'" do
|
231
|
-
expect(subject.usage.last).to eq("#{long}=#{subject.value.usage}")
|
232
|
-
end
|
233
|
-
|
234
|
-
context "but the #value is also optional?" do
|
235
|
-
let(:value_required) { false }
|
236
|
-
|
237
|
-
it "must return '--option[=USAGE]'" do
|
238
|
-
expect(subject.usage.last).to eq("#{long}[=#{subject.value.usage}]")
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
context "when #short is not nil" do
|
245
|
-
let(:short) { '-f' }
|
246
|
-
|
247
|
-
it "to have two elements" do
|
248
|
-
expect(subject.usage.length).to eq(2)
|
249
|
-
end
|
250
|
-
|
251
|
-
it "the first element should be the short option" do
|
252
|
-
expect(subject.usage[0]).to eq(short)
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
describe "#value?" do
|
258
|
-
context "when #value has been initialized" do
|
259
|
-
let(:value) { {} }
|
260
|
-
|
261
|
-
it { expect(subject.value?).to be(true) }
|
262
|
-
end
|
263
|
-
|
264
|
-
context "when #value has not been initialized" do
|
265
|
-
let(:value) { nil }
|
266
|
-
|
267
|
-
it { expect(subject.value?).to be(false) }
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
describe "#type" do
|
272
|
-
context "when #value has been initialized and has a #type" do
|
273
|
-
let(:type) { String }
|
274
|
-
let(:value) { {type: type} }
|
275
|
-
|
276
|
-
it "must return the #value.type" do
|
277
|
-
expect(subject.type).to eq(type)
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
context "when #value has not been initialized" do
|
282
|
-
let(:value) { nil }
|
283
|
-
|
284
|
-
it { expect(subject.type).to be(nil) }
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
describe "#default_value" do
|
289
|
-
context "when #value has been initialized and has a #default" do
|
290
|
-
let(:default) { "" }
|
291
|
-
let(:value) { {default: default} }
|
292
|
-
|
293
|
-
it "must return the #value.default_value" do
|
294
|
-
expect(subject.default_value).to eq(default)
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
context "when #value has not been initialized" do
|
299
|
-
let(:value) { nil }
|
300
|
-
|
301
|
-
it { expect(subject.default_value).to be(nil) }
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
describe "#desc" do
|
306
|
-
let(:desc) { 'Foo option' }
|
307
|
-
|
308
|
-
it "must return the desc: value" do
|
309
|
-
expect(subject.desc).to eq(desc)
|
310
|
-
end
|
311
|
-
|
312
|
-
context "when #value has been initialized with a default value" do
|
313
|
-
let(:default) { "foo" }
|
314
|
-
let(:value) { {default: default} }
|
315
|
-
|
316
|
-
it "should reutrn the desc value and '(Default: ...)'" do
|
317
|
-
expect(subject.desc).to eq("#{desc} (Default: #{default})")
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
context "when #desc was initialized with an Array" do
|
322
|
-
let(:desc) do
|
323
|
-
[
|
324
|
-
'Line 1',
|
325
|
-
'Line 2'
|
326
|
-
]
|
327
|
-
end
|
328
|
-
|
329
|
-
it "must return the desc: value" do
|
330
|
-
expect(subject.desc).to eq(desc)
|
331
|
-
end
|
332
|
-
|
333
|
-
context "when #value has been initialized with a default value" do
|
334
|
-
let(:default) { "foo" }
|
335
|
-
let(:value) { {default: default} }
|
336
|
-
|
337
|
-
it "should append '(Default: ...)' to the desc Array" do
|
338
|
-
expect(subject.desc).to eq([*desc, "(Default: #{default})"])
|
339
|
-
end
|
340
|
-
end
|
341
|
-
end
|
342
|
-
end
|
343
|
-
end
|