command_kit 0.4.0 → 0.5.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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -0
- data/.rubocop.yml +3 -0
- data/ChangeLog.md +18 -0
- data/LICENSE.txt +1 -1
- data/README.md +4 -1
- data/command_kit.gemspec +7 -2
- data/examples/subcommands/cli/config/get.rb +47 -0
- data/examples/subcommands/cli/config/set.rb +44 -0
- data/examples/subcommands/cli/config.rb +23 -0
- data/examples/subcommands/cli/list.rb +35 -0
- data/examples/subcommands/cli/update.rb +47 -0
- data/examples/subcommands/cli.rb +55 -0
- data/lib/command_kit/completion/install.rb +276 -0
- data/lib/command_kit/env/home.rb +1 -1
- data/lib/command_kit/env/prefix.rb +41 -0
- data/lib/command_kit/env/shell.rb +58 -0
- data/lib/command_kit/inflector.rb +1 -1
- data/lib/command_kit/options/parser.rb +1 -1
- data/lib/command_kit/os/linux.rb +1 -1
- data/lib/command_kit/os.rb +1 -1
- data/lib/command_kit/printing/tables/table_formatter.rb +2 -2
- data/lib/command_kit/version.rb +1 -1
- data/lib/command_kit/xdg.rb +1 -1
- metadata +12 -66
- 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 -839
- 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 -255
- 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 -1180
- 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
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'command_kit/env'
|
4
|
+
|
5
|
+
module CommandKit
|
6
|
+
module Env
|
7
|
+
#
|
8
|
+
# Methods related to the `PREFIX` environment variable.
|
9
|
+
#
|
10
|
+
# ## Environment Variables
|
11
|
+
#
|
12
|
+
# * `PREFIX` - The optional root prefix of the file-system.
|
13
|
+
#
|
14
|
+
# @since 0.5.0
|
15
|
+
#
|
16
|
+
module Prefix
|
17
|
+
include Env
|
18
|
+
|
19
|
+
# The root of the file-system.
|
20
|
+
#
|
21
|
+
# @return [String]
|
22
|
+
# The `PREFIX` environment variable, or `/` if no `PREFIX` environment
|
23
|
+
# variable is given.
|
24
|
+
attr_reader :root
|
25
|
+
|
26
|
+
#
|
27
|
+
# Initialize {#root} based on the `PREFIX` environment
|
28
|
+
#
|
29
|
+
# @param [Hash{Symbol => Object}] kwargs
|
30
|
+
# Additional keyword arguments.
|
31
|
+
#
|
32
|
+
# @api public
|
33
|
+
#
|
34
|
+
def initialize(**kwargs)
|
35
|
+
super(**kwargs)
|
36
|
+
|
37
|
+
@root = env.fetch('PREFIX','/')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'command_kit/env'
|
4
|
+
|
5
|
+
module CommandKit
|
6
|
+
module Env
|
7
|
+
#
|
8
|
+
# Methods related to the `SHELL` environment variable.
|
9
|
+
#
|
10
|
+
# ## Environment Variables
|
11
|
+
#
|
12
|
+
# * `SHELL` - The current shell.
|
13
|
+
#
|
14
|
+
# @since 0.5.0
|
15
|
+
#
|
16
|
+
module Shell
|
17
|
+
include Env
|
18
|
+
|
19
|
+
# The current shell.
|
20
|
+
#
|
21
|
+
# @return [String, nil]
|
22
|
+
attr_reader :shell
|
23
|
+
|
24
|
+
# The current shell type.
|
25
|
+
#
|
26
|
+
# @return [:bash, :zsh, :fish, :dash, :mksh, :ksh, :tcsh, :csh, :sh, nil]
|
27
|
+
attr_reader :shell_type
|
28
|
+
|
29
|
+
#
|
30
|
+
# Initialize {#shell} and {#shell_type} based on the `SHELL` environment
|
31
|
+
# variable.
|
32
|
+
#
|
33
|
+
# @param [Hash{Symbol => Object}] kwargs
|
34
|
+
# Additional keyword arguments.
|
35
|
+
#
|
36
|
+
# @api public
|
37
|
+
#
|
38
|
+
def initialize(**kwargs)
|
39
|
+
super(**kwargs)
|
40
|
+
|
41
|
+
@shell = env['SHELL']
|
42
|
+
@shell_type = if @shell
|
43
|
+
case File.basename(@shell)
|
44
|
+
when /bash/ then :bash
|
45
|
+
when /zsh/ then :zsh
|
46
|
+
when /fish/ then :fish
|
47
|
+
when /dash/ then :dash
|
48
|
+
when /mksh/ then :mksh
|
49
|
+
when /ksh/ then :ksh
|
50
|
+
when /tcsh/ then :tcsh
|
51
|
+
when /csh/ then :csh
|
52
|
+
when /sh/ then :sh
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -103,7 +103,7 @@ module CommandKit
|
|
103
103
|
new_string << word
|
104
104
|
elsif scanner.scan(/[_-]+/)
|
105
105
|
# skip
|
106
|
-
elsif scanner.scan(
|
106
|
+
elsif scanner.scan(%r{/})
|
107
107
|
new_string << '::'
|
108
108
|
else
|
109
109
|
raise(ArgumentError,"cannot convert string to CamelCase: #{scanner.string.inspect}")
|
data/lib/command_kit/os/linux.rb
CHANGED
@@ -36,7 +36,7 @@ module CommandKit
|
|
36
36
|
module ModuleMethods
|
37
37
|
#
|
38
38
|
# Extends {ClassMethods} or {ModuleMethods}, depending on whether
|
39
|
-
# {OS} is being included into a class or a module
|
39
|
+
# {OS} is being included into a class or a module.
|
40
40
|
#
|
41
41
|
# @param [Class, Module] context
|
42
42
|
# The class or module which is including {OS}.
|
data/lib/command_kit/os.rb
CHANGED
@@ -32,7 +32,7 @@ module CommandKit
|
|
32
32
|
module ModuleMethods
|
33
33
|
#
|
34
34
|
# Extends {ClassMethods} or {ModuleMethods}, depending on whether
|
35
|
-
# {OS} is being included into a class or a module
|
35
|
+
# {OS} is being included into a class or a module.
|
36
36
|
#
|
37
37
|
# @param [Class, Module] context
|
38
38
|
# The class or module which is including {OS}.
|
@@ -87,7 +87,7 @@ module CommandKit
|
|
87
87
|
column_border: ,
|
88
88
|
joined_border: ,
|
89
89
|
right_border: )
|
90
|
-
line = String.new
|
90
|
+
line = String.new(encoding: Encoding::UTF_8)
|
91
91
|
line << left_border
|
92
92
|
|
93
93
|
@table.max_columns.times do |column_index|
|
@@ -191,7 +191,7 @@ module CommandKit
|
|
191
191
|
# The formatted row line.
|
192
192
|
#
|
193
193
|
def format_row_line(row,line_index, justify: @style.justify)
|
194
|
-
line = String.new
|
194
|
+
line = String.new(encoding: Encoding::UTF_8)
|
195
195
|
line << @style.border.left_border if @style.border
|
196
196
|
|
197
197
|
@table.max_columns.times do |column_index|
|
data/lib/command_kit/version.rb
CHANGED
data/lib/command_kit/xdg.rb
CHANGED
@@ -30,7 +30,7 @@ module CommandKit
|
|
30
30
|
module ModuleMethods
|
31
31
|
#
|
32
32
|
# Extends {ClassMethods} or {ModuleMethods}, depending on whether {XDG} is
|
33
|
-
# being included into a class or a module
|
33
|
+
# being included into a class or a module.
|
34
34
|
#
|
35
35
|
# @param [Class, Module] context
|
36
36
|
# The class or module which is including {XDG}.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: command_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -50,6 +50,12 @@ files:
|
|
50
50
|
- examples/command.rb
|
51
51
|
- examples/pager.rb
|
52
52
|
- examples/printing/tables.rb
|
53
|
+
- examples/subcommands/cli.rb
|
54
|
+
- examples/subcommands/cli/config.rb
|
55
|
+
- examples/subcommands/cli/config/get.rb
|
56
|
+
- examples/subcommands/cli/config/set.rb
|
57
|
+
- examples/subcommands/cli/list.rb
|
58
|
+
- examples/subcommands/cli/update.rb
|
53
59
|
- gemspec.yml
|
54
60
|
- lib/command_kit.rb
|
55
61
|
- lib/command_kit/arguments.rb
|
@@ -67,11 +73,14 @@ files:
|
|
67
73
|
- lib/command_kit/commands/help.rb
|
68
74
|
- lib/command_kit/commands/parent_command.rb
|
69
75
|
- lib/command_kit/commands/subcommand.rb
|
76
|
+
- lib/command_kit/completion/install.rb
|
70
77
|
- lib/command_kit/description.rb
|
71
78
|
- lib/command_kit/edit.rb
|
72
79
|
- lib/command_kit/env.rb
|
73
80
|
- lib/command_kit/env/home.rb
|
74
81
|
- lib/command_kit/env/path.rb
|
82
|
+
- lib/command_kit/env/prefix.rb
|
83
|
+
- lib/command_kit/env/shell.rb
|
75
84
|
- lib/command_kit/examples.rb
|
76
85
|
- lib/command_kit/exception_handler.rb
|
77
86
|
- lib/command_kit/file_utils.rb
|
@@ -111,69 +120,6 @@ files:
|
|
111
120
|
- lib/command_kit/usage.rb
|
112
121
|
- lib/command_kit/version.rb
|
113
122
|
- lib/command_kit/xdg.rb
|
114
|
-
- spec/arguments/argument_spec.rb
|
115
|
-
- spec/arguments/argument_value_spec.rb
|
116
|
-
- spec/arguments_spec.rb
|
117
|
-
- spec/bug_report_spec.rb
|
118
|
-
- spec/colors_spec.rb
|
119
|
-
- spec/command_kit_spec.rb
|
120
|
-
- spec/command_name_spec.rb
|
121
|
-
- spec/command_spec.rb
|
122
|
-
- spec/commands/auto_load/subcommand_spec.rb
|
123
|
-
- spec/commands/auto_load_spec.rb
|
124
|
-
- spec/commands/auto_require_spec.rb
|
125
|
-
- spec/commands/fixtures/test_auto_load/cli/commands/test1.rb
|
126
|
-
- spec/commands/fixtures/test_auto_load/cli/commands/test2.rb
|
127
|
-
- spec/commands/fixtures/test_auto_require/lib/test_auto_require/cli/commands/test1.rb
|
128
|
-
- spec/commands/help_spec.rb
|
129
|
-
- spec/commands/parent_command_spec.rb
|
130
|
-
- spec/commands/subcommand_spec.rb
|
131
|
-
- spec/commands_spec.rb
|
132
|
-
- spec/description_spec.rb
|
133
|
-
- spec/edit_spec.rb
|
134
|
-
- spec/env/home_spec.rb
|
135
|
-
- spec/env/path_spec.rb
|
136
|
-
- spec/env_spec.rb
|
137
|
-
- spec/examples_spec.rb
|
138
|
-
- spec/exception_handler_spec.rb
|
139
|
-
- spec/file_utils_spec.rb
|
140
|
-
- spec/fixtures/template.erb
|
141
|
-
- spec/help/man_spec.rb
|
142
|
-
- spec/help_spec.rb
|
143
|
-
- spec/inflector_spec.rb
|
144
|
-
- spec/interactive_spec.rb
|
145
|
-
- spec/main_spec.rb
|
146
|
-
- spec/man_spec.rb
|
147
|
-
- spec/open_app_spec.rb
|
148
|
-
- spec/options/option_spec.rb
|
149
|
-
- spec/options/option_value_spec.rb
|
150
|
-
- spec/options/parser_spec.rb
|
151
|
-
- spec/options/quiet_spec.rb
|
152
|
-
- spec/options/verbose_spec.rb
|
153
|
-
- spec/options/version_spec.rb
|
154
|
-
- spec/options_spec.rb
|
155
|
-
- spec/os/linux_spec.rb
|
156
|
-
- spec/os_spec.rb
|
157
|
-
- spec/package_manager_spec.rb
|
158
|
-
- spec/pager_spec.rb
|
159
|
-
- spec/printing/fields_spec.rb
|
160
|
-
- spec/printing/indent_spec.rb
|
161
|
-
- spec/printing/lists_spec.rb
|
162
|
-
- spec/printing/tables/border_style.rb
|
163
|
-
- spec/printing/tables/cell_builer_spec.rb
|
164
|
-
- spec/printing/tables/row_builder_spec.rb
|
165
|
-
- spec/printing/tables/style_spec.rb
|
166
|
-
- spec/printing/tables/table_builder_spec.rb
|
167
|
-
- spec/printing/tables/table_formatter_spec.rb
|
168
|
-
- spec/printing/tables_spec.rb
|
169
|
-
- spec/printing_spec.rb
|
170
|
-
- spec/program_name_spec.rb
|
171
|
-
- spec/spec_helper.rb
|
172
|
-
- spec/stdio_spec.rb
|
173
|
-
- spec/sudo_spec.rb
|
174
|
-
- spec/terminal_spec.rb
|
175
|
-
- spec/usage_spec.rb
|
176
|
-
- spec/xdg_spec.rb
|
177
123
|
homepage: https://github.com/postmodern/command_kit.rb#readme
|
178
124
|
licenses:
|
179
125
|
- MIT
|
@@ -198,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
144
|
- !ruby/object:Gem::Version
|
199
145
|
version: '0'
|
200
146
|
requirements: []
|
201
|
-
rubygems_version: 3.
|
147
|
+
rubygems_version: 3.4.10
|
202
148
|
signing_key:
|
203
149
|
specification_version: 4
|
204
150
|
summary: An all-in-one modular Ruby CLI toolkit
|
@@ -1,133 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'command_kit/arguments/argument'
|
3
|
-
|
4
|
-
describe CommandKit::Arguments::Argument do
|
5
|
-
let(:name) { :foo }
|
6
|
-
let(:usage) { 'FOO' }
|
7
|
-
let(:required) { true }
|
8
|
-
let(:repeats) { false }
|
9
|
-
let(:desc) { 'Foo argument' }
|
10
|
-
|
11
|
-
subject do
|
12
|
-
described_class.new name, usage: usage,
|
13
|
-
required: required,
|
14
|
-
repeats: repeats,
|
15
|
-
desc: desc
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "#initialize" do
|
19
|
-
context "when the usage: keyword is given" do
|
20
|
-
subject { described_class.new(name, usage: usage, desc: desc) }
|
21
|
-
|
22
|
-
it "must include usage: in #usage" do
|
23
|
-
expect(subject.usage).to include(usage)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when the usage: keyword is not given" do
|
28
|
-
subject { described_class.new(name, desc: desc) }
|
29
|
-
|
30
|
-
it "should use uppercased argument name in #usage" do
|
31
|
-
expect(subject.usage).to include(name.to_s.upcase)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when the required: keyword is given" do
|
36
|
-
subject { described_class.new(name, required: required, desc: desc) }
|
37
|
-
|
38
|
-
it "must set #required" do
|
39
|
-
expect(subject.required).to eq(required)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "when the required: keyword is not given" do
|
44
|
-
subject { described_class.new(name, desc: desc) }
|
45
|
-
|
46
|
-
it "default #required to String" do
|
47
|
-
expect(subject.required).to eq(true)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "when the repeats: keyword is given" do
|
52
|
-
subject { described_class.new(name, repeats: repeats, desc: desc) }
|
53
|
-
|
54
|
-
it "must set #repeats" do
|
55
|
-
expect(subject.repeats?).to eq(repeats)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "when the repeats: keyword is not given" do
|
60
|
-
subject { described_class.new(name, desc: desc) }
|
61
|
-
|
62
|
-
it "default #repeats to String" do
|
63
|
-
expect(subject.repeats?).to eq(false)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when the desc: keyword is given" do
|
68
|
-
subject { described_class.new(name, desc: desc) }
|
69
|
-
|
70
|
-
it "must set #desc" do
|
71
|
-
expect(subject.desc).to eq(desc)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "when the desc: keyword is not given" do
|
76
|
-
it do
|
77
|
-
expect {
|
78
|
-
described_class.new(name)
|
79
|
-
}.to raise_error(ArgumentError)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "#repeats?" do
|
85
|
-
context "when initialized with repeats: true" do
|
86
|
-
let(:repeats) { true }
|
87
|
-
|
88
|
-
it { expect(subject.repeats?).to be(true) }
|
89
|
-
end
|
90
|
-
|
91
|
-
context "when initialized with repeats: false" do
|
92
|
-
let(:repeats) { false }
|
93
|
-
|
94
|
-
it { expect(subject.repeats?).to be(false) }
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "#usage" do
|
99
|
-
let(:usage) { 'FOO' }
|
100
|
-
|
101
|
-
context "initialized with required: true" do
|
102
|
-
let(:required) { true }
|
103
|
-
|
104
|
-
it "must return the usage unchanged" do
|
105
|
-
expect(subject.usage).to eq(usage)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context "initialized with required: false" do
|
110
|
-
let(:required) { false }
|
111
|
-
|
112
|
-
it "must wrap the usage in [ ] brackets" do
|
113
|
-
expect(subject.usage).to eq("[#{usage}]")
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context "initialized with repeats: true" do
|
118
|
-
let(:repeats) { true }
|
119
|
-
|
120
|
-
it "must append the ... ellipses" do
|
121
|
-
expect(subject.usage).to eq("#{usage} ...")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "initialized with repeats: false" do
|
126
|
-
let(:repeats) { false }
|
127
|
-
|
128
|
-
it "must return the usage name unchanged" do
|
129
|
-
expect(subject.usage).to eq(usage)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'command_kit/arguments/argument_value'
|
3
|
-
|
4
|
-
describe CommandKit::Arguments::ArgumentValue do
|
5
|
-
let(:required) { false }
|
6
|
-
let(:usage) { 'FOO' }
|
7
|
-
|
8
|
-
subject do
|
9
|
-
described_class.new(
|
10
|
-
required: required,
|
11
|
-
usage: usage
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#initialize" do
|
16
|
-
it "must require a usage: keyword"do
|
17
|
-
expect {
|
18
|
-
described_class.new(required: required)
|
19
|
-
}.to raise_error(ArgumentError)
|
20
|
-
end
|
21
|
-
|
22
|
-
context "when required: is given" do
|
23
|
-
subject { described_class.new(required: required, usage: usage) }
|
24
|
-
|
25
|
-
it "must set #required" do
|
26
|
-
expect(subject.required).to eq(required)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "when required: is not given" do
|
31
|
-
subject { described_class.new(usage: usage) }
|
32
|
-
|
33
|
-
it "must default to true" do
|
34
|
-
expect(subject.required).to be(true)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "#required?" do
|
40
|
-
context "when required: is initialized with true" do
|
41
|
-
let(:required) { true }
|
42
|
-
|
43
|
-
it { expect(subject.required?).to be(true) }
|
44
|
-
end
|
45
|
-
|
46
|
-
context "when required: is initialized with false" do
|
47
|
-
let(:required) { false }
|
48
|
-
|
49
|
-
it { expect(subject.required?).to be(false) }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#optional?" do
|
54
|
-
context "when required: is initialized with true" do
|
55
|
-
let(:required) { true }
|
56
|
-
|
57
|
-
it { expect(subject.optional?).to be(false) }
|
58
|
-
end
|
59
|
-
|
60
|
-
context "when required: is initialized with false" do
|
61
|
-
let(:required) { false }
|
62
|
-
|
63
|
-
it { expect(subject.optional?).to be(true) }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|