Skip to content

Commit 49188d2

Browse files
committed
move introspection specs to their respective folder
1 parent 3414743 commit 49188d2

File tree

9 files changed

+340
-280
lines changed

9 files changed

+340
-280
lines changed

lib/bashly/script/introspection/environment_variables.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ def required_environment_variables
2626
environment_variables.select(&:required)
2727
end
2828

29-
# Returns an array of all the environment_variables with a whitelist arg
30-
def whitelisted_environment_variables
31-
environment_variables.select(&:allowed)
32-
end
33-
3429
# Returns an array of all the environment_variables with a validation
3530
def validated_environment_variables
3631
environment_variables.select(&:validate)
3732
end
33+
34+
# Returns an array of all the environment_variables with a whitelist arg
35+
def whitelisted_environment_variables
36+
environment_variables.select(&:allowed)
37+
end
3838
end
3939
end
4040
end

lib/bashly/script/introspection/flags.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ def global_flags?
2222
flags.any? and commands.any?
2323
end
2424

25+
# Returns an array of all fpags that need other flags
26+
def needy_flags
27+
flags.select(&:needs)
28+
end
29+
2530
# Returns only flags that are not private
2631
def public_flags
2732
flags.reject(&:private)
@@ -32,11 +37,6 @@ def required_flags
3237
flags.select(&:required)
3338
end
3439

35-
# Returns an array of all fpags that need other flags
36-
def needy_flags
37-
flags.select(&:needs)
38-
end
39-
4040
# Returns true if one of the flags matches the provided short code
4141
def short_flag_exist?(flag)
4242
flags.any? { |f| f.short == flag }

spec/bashly/script/command_spec.rb

Lines changed: 0 additions & 270 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@
4848
end
4949
end
5050

51-
describe '#args' do
52-
it 'returns an array of Argument objects' do
53-
expect(subject.args).to be_an Array
54-
expect(subject.args.first).to be_a Script::Argument
55-
end
56-
end
57-
5851
describe '#caption_string' do
5952
it 'returns a string containing the name and summary' do
6053
expect(subject.caption_string).to eq 'get - get something from somewhere'
@@ -69,129 +62,6 @@
6962
end
7063
end
7164

72-
describe '#command_aliases' do
73-
let(:fixture) { :aliases }
74-
75-
it 'returns an array of command aliases' do
76-
expect(subject.command_aliases).to eq %w[download d pull upload u push update upgrade]
77-
end
78-
end
79-
80-
describe '#command_help_data' do
81-
let(:fixture) { :exposed }
82-
83-
it 'returns a hash suitable for showing command and exposed subcommand help' do
84-
expect(subject.command_help_data.to_yaml)
85-
.to match_approval('script/command/exposed_commands')
86-
end
87-
end
88-
89-
describe '#command_names' do
90-
let(:fixture) { :docker }
91-
92-
it 'returns an array of command names' do
93-
expect(subject.command_names).to eq %w[container image]
94-
end
95-
end
96-
97-
describe '#commands' do
98-
let(:fixture) { :docker }
99-
100-
it 'returns an array of Command objects' do
101-
expect(subject.commands).to be_an Array
102-
expect(subject.commands.first).to be_a described_class
103-
end
104-
105-
it 'sets the parents property of its commands' do
106-
expect(subject.commands.first.parents).to eq ['docker']
107-
end
108-
end
109-
110-
describe '#deep_commands' do
111-
let(:fixture) { :docker }
112-
113-
it 'returns an array of all commands in the tree' do
114-
expect(subject.deep_commands.map(&:full_name))
115-
.to eq ['docker container', 'docker container run', 'docker container stop', 'docker image']
116-
end
117-
118-
context 'when include_self is true' do
119-
it 'prepends the result with the command itself' do
120-
expect(subject.deep_commands(include_self: true).map(&:full_name))
121-
.to eq ['docker', 'docker container', 'docker container run', 'docker container stop', 'docker image']
122-
end
123-
end
124-
end
125-
126-
describe '#default_arguments' do
127-
let(:fixture) { :default_values }
128-
129-
it 'returns an array of only the Argument objects that have default' do
130-
expect(subject.default_args.size).to eq 1
131-
expect(subject.default_args.first.name).to eq 'files'
132-
end
133-
end
134-
135-
describe '#default_command' do
136-
let(:fixture) { :default_command }
137-
138-
it 'returns a Command object of the first default command' do
139-
expect(subject.default_command).to be_a described_class
140-
expect(subject.default_command.name).to eq 'get'
141-
end
142-
end
143-
144-
describe '#default_flags' do
145-
let(:fixture) { :default_values }
146-
147-
it 'returns an array of only the Flags objects that have default' do
148-
expect(subject.default_flags.size).to eq 1
149-
expect(subject.default_flags.first.long).to eq '--format'
150-
end
151-
end
152-
153-
describe '#dependencies' do
154-
let(:fixture) { :dependencies }
155-
156-
it 'returns an array of Dependency objects' do
157-
expect(subject.dependencies).to be_an Array
158-
expect(subject.dependencies.first).to be_a Script::Dependency
159-
end
160-
end
161-
162-
describe '#environment_cariables' do
163-
it 'returns an array of EnvironmentVariable objects' do
164-
expect(subject.environment_variables).to be_an Array
165-
expect(subject.environment_variables.first).to be_a Script::EnvironmentVariable
166-
end
167-
end
168-
169-
describe '#examples' do
170-
context 'when there are no examples' do
171-
it 'returns nil' do
172-
expect(subject.examples).to be_nil
173-
end
174-
end
175-
176-
context 'when there are examples as array' do
177-
let(:fixture) { :examples_array }
178-
179-
it 'returns the array' do
180-
expect(subject.examples).to be_an Array
181-
end
182-
end
183-
184-
context 'when there are examples as string' do
185-
let(:fixture) { :examples_string }
186-
187-
it 'returns an array with one item' do
188-
expect(subject.examples).to be_an Array
189-
expect(subject.examples.count).to eq 1
190-
expect(subject.examples.first).to start_with 'Download a file'
191-
end
192-
end
193-
end
194-
19565
describe '#filename' do
19666
context 'when it is the root command' do
19767
it 'returns root_command.sh' do
@@ -251,13 +121,6 @@
251121
end
252122
end
253123

254-
describe '#flags' do
255-
it 'returns an array of Flag objects' do
256-
expect(subject.flags).to be_an Array
257-
expect(subject.flags.first).to be_a Script::Flag
258-
end
259-
end
260-
261124
describe '#function_name' do
262125
let(:fixture) { :docker_container_run }
263126

@@ -290,32 +153,6 @@
290153
end
291154
end
292155

293-
describe '#global_flags?' do
294-
context 'when a command has flags and commands' do
295-
let(:fixture) { :mode_global_flags }
296-
297-
it 'returns true' do
298-
expect(subject).to be_global_flags
299-
end
300-
end
301-
302-
context 'when a command has flags but no commands' do
303-
let(:fixture) { :mode_flags }
304-
305-
it 'returns false' do
306-
expect(subject).not_to be_global_flags
307-
end
308-
end
309-
310-
context 'when a command has commands but no flags' do
311-
let(:fixture) { :mode_commands }
312-
313-
it 'returns false' do
314-
expect(subject).not_to be_global_flags
315-
end
316-
end
317-
end
318-
319156
describe '#group_string' do
320157
it 'returns a string suitable for showing the group in usage' do
321158
expect(subject.group_string).to eq 'Commands:'
@@ -330,16 +167,6 @@
330167
end
331168
end
332169

333-
describe '#grouped_commands' do
334-
let(:fixture) { :exposed }
335-
336-
it 'returns a hash with an array of Command objects per group key' do
337-
expect(subject.grouped_commands.keys).to contain_exactly('Cluster Commands:', 'Commands:')
338-
expect(subject.grouped_commands['Commands:'].count).to eq 4
339-
expect(subject.grouped_commands['Commands:']).to all(be_a described_class)
340-
end
341-
end
342-
343170
describe '#has_unique_args_or_flags?' do
344171
context 'when the command has any args that are unique' do
345172
let(:fixture) { :unique_args }
@@ -455,69 +282,6 @@
455282
end
456283
end
457284

458-
describe '#needy_flags' do
459-
let(:fixture) { :needy_flags }
460-
461-
it 'returns an array of only the needy Flag objects' do
462-
expect(subject.needy_flags.size).to eq 2
463-
expect(subject.needy_flags.first.long).to eq '--add'
464-
end
465-
end
466-
467-
describe '#public_commands' do
468-
let(:fixture) { :private_commands }
469-
470-
it 'returns an array of Command objects excluding private commands' do
471-
expect(subject.public_commands.count).to eq 1
472-
expect(subject.public_commands.first.name).to eq 'connect'
473-
end
474-
end
475-
476-
describe '#public_commands_aliases' do
477-
let(:fixture) { :private_commands }
478-
479-
it 'returns an array of command aliases of public subcommands' do
480-
expect(subject.public_command_aliases).to eq %w[connect c]
481-
end
482-
end
483-
484-
describe '#required_args' do
485-
it 'returns an array of only the required Argument objects' do
486-
expect(subject.required_args.size).to eq 1
487-
expect(subject.required_args.first.name).to eq 'source'
488-
end
489-
end
490-
491-
describe '#required_environment_variables' do
492-
it 'returns an array of only the required Argument objects' do
493-
expect(subject.required_environment_variables.size).to eq 1
494-
expect(subject.required_environment_variables.first.name).to eq 'secret_key'
495-
end
496-
end
497-
498-
describe '#required_flags' do
499-
it 'returns an array of only the required Flag objects' do
500-
expect(subject.required_flags.size).to eq 1
501-
expect(subject.required_flags.first.long).to eq '--force'
502-
end
503-
end
504-
505-
describe '#repeatable_arg_exist?' do
506-
context 'when the command does not have any repeatable flags' do
507-
it 'returns false' do
508-
expect(subject.repeatable_arg_exist?).to be false
509-
end
510-
end
511-
512-
context 'when the command has at least one repeatable flag' do
513-
let(:fixture) { :repeatable_arg }
514-
515-
it 'returns true' do
516-
expect(subject.repeatable_arg_exist?).to be true
517-
end
518-
end
519-
end
520-
521285
describe '#root_command?' do
522286
context 'when the command has no parents' do
523287
it 'returns true' do
@@ -534,22 +298,6 @@
534298
end
535299
end
536300

537-
describe '#short_flag_exist?' do
538-
let(:fixture) { :flag_hog }
539-
540-
context 'when the command has this short flag' do
541-
it 'returns true' do
542-
expect(subject.short_flag_exist?('-h')).to be true
543-
end
544-
end
545-
546-
context 'when the command does not have this short flag' do
547-
it 'returns false' do
548-
expect(subject.short_flag_exist?('-s')).to be false
549-
end
550-
end
551-
end
552-
553301
describe '#summary_string' do
554302
it 'returns the user defined summary' do
555303
expect(subject.summary_string).to eq 'get something from somewhere'
@@ -678,22 +426,4 @@
678426
end
679427
end
680428
end
681-
682-
describe '#whitelisted_args' do
683-
let(:fixture) { :whitelist }
684-
685-
it 'returns an array of args that have a whitelist' do
686-
expect(subject.whitelisted_args.size).to eq 1
687-
expect(subject.whitelisted_args.first.name).to eq 'region'
688-
end
689-
end
690-
691-
describe '#whitelisted_flags' do
692-
let(:fixture) { :whitelist }
693-
694-
it 'returns an array of flags that have a whitelist' do
695-
expect(subject.whitelisted_flags.size).to eq 1
696-
expect(subject.whitelisted_flags.first.long).to eq '--user'
697-
end
698-
end
699429
end

0 commit comments

Comments
 (0)