Skip to content

Commit 5467f7c

Browse files
committed
backfill missing introspection specs
1 parent 49188d2 commit 5467f7c

File tree

6 files changed

+93
-22
lines changed

6 files changed

+93
-22
lines changed

lib/bashly/script/introspection/environment_variables.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Bashly
22
module Script
33
module Introspection
44
module EnvironmentVariables
5-
# Returns an array of all the default Environment Variables
5+
# Returns an array of all the Environment Variables with default values
66
def default_environment_variables
77
environment_variables.select(&:default)
88
end

spec/approvals/cli/doc/full

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,12 +539,23 @@ environment_variable.required
539539

540540
Specify that this variable is required.
541541

542+
environment_variables:
542543
- name: api_key
543544
help: Your API key
544545
required: true
545546

546547
See https://bashly.dannyb.co/configuration/environment-variable/#required
547548

549+
environment_variable.validate
550+
551+
Apply custom validation functions.
552+
553+
environment_variables:
554+
- name: build_dir
555+
validate: dir_exists
556+
557+
See https://bashly.dannyb.co/configuration/environment-variable/#validate
558+
548559
flag
549560

550561
Define option flags.

spec/approvals/cli/doc/index

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ environment_variable.help
3434
environment_variable.name
3535
environment_variable.private
3636
environment_variable.required
37+
environment_variable.validate
3738
flag
3839
flag.allowed
3940
flag.arg

spec/bashly/script/introspection/environment_variables_spec.rb

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,47 @@
66
end
77

88
let(:fixtures) { load_fixture 'script/commands' }
9-
let(:fixture) { :basic_command }
9+
let(:fixture) { :environment_variable_enthusiast }
1010

11-
describe '#environment_cariables' do
11+
describe '#default_environment_variables' do
12+
it 'returns an array of all the Environment Variables with default values' do
13+
expect(subject.default_environment_variables.size).to eq 1
14+
expect(subject.default_environment_variables.first.name).to eq 'file'
15+
end
16+
end
17+
18+
describe '#environment_variables' do
1219
it 'returns an array of EnvironmentVariable objects' do
1320
expect(subject.environment_variables).to be_an Array
14-
expect(subject.environment_variables.first).to be_a Script::EnvironmentVariable
21+
expect(subject.environment_variables).to all(be_a Script::EnvironmentVariable)
22+
end
23+
end
24+
25+
describe '#public_environment_variables' do
26+
it 'returns only environment variables that are not private' do
27+
expect(subject.public_environment_variables.size).to eq 4
28+
expect(subject.public_environment_variables.map(&:name)).not_to include 'secret'
1529
end
1630
end
1731

1832
describe '#required_environment_variables' do
1933
it 'returns an array of only the required Argument objects' do
2034
expect(subject.required_environment_variables.size).to eq 1
21-
expect(subject.required_environment_variables.first.name).to eq 'secret_key'
35+
expect(subject.required_environment_variables.first.name).to eq 'username'
36+
end
37+
end
38+
39+
describe '#validated_environment_variables' do
40+
it 'returns an array of all the environment variables with a validation' do
41+
expect(subject.validated_environment_variables.size).to eq 1
42+
expect(subject.validated_environment_variables.first.name).to eq 'config_dir'
43+
end
44+
end
45+
46+
describe '#whitelisted_environment_variables' do
47+
it 'returns an array of all the environment_variables with a whitelist arg' do
48+
expect(subject.whitelisted_environment_variables.size).to eq 1
49+
expect(subject.whitelisted_environment_variables.first.name).to eq 'protocol'
2250
end
2351
end
2452
end

spec/bashly/script/introspection/flags_spec.rb

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,28 @@
5050
end
5151
end
5252

53-
describe '#whitelisted_flags' do
54-
let(:fixture) { :whitelist }
53+
describe '#needy_flags' do
54+
let(:fixture) { :needy_flags }
5555

56-
it 'returns an array of flags that have a whitelist' do
57-
expect(subject.whitelisted_flags.size).to eq 1
58-
expect(subject.whitelisted_flags.first.long).to eq '--user'
56+
it 'returns an array of only the needy Flag objects' do
57+
expect(subject.needy_flags.size).to eq 2
58+
expect(subject.needy_flags.first.long).to eq '--add'
59+
end
60+
end
61+
62+
describe '#public_flags' do
63+
let(:fixture) { :private_flags }
64+
65+
it 'returns an array of only the non private Flag objects' do
66+
expect(subject.public_flags.size).to eq 1
67+
expect(subject.public_flags.first.long).to eq '--new'
68+
end
69+
end
70+
71+
describe '#required_flags' do
72+
it 'returns an array of only the required Flag objects' do
73+
expect(subject.required_flags.size).to eq 1
74+
expect(subject.required_flags.first.long).to eq '--force'
5975
end
6076
end
6177

@@ -75,19 +91,12 @@
7591
end
7692
end
7793

78-
describe '#needy_flags' do
79-
let(:fixture) { :needy_flags }
80-
81-
it 'returns an array of only the needy Flag objects' do
82-
expect(subject.needy_flags.size).to eq 2
83-
expect(subject.needy_flags.first.long).to eq '--add'
84-
end
85-
end
94+
describe '#whitelisted_flags' do
95+
let(:fixture) { :whitelist }
8696

87-
describe '#required_flags' do
88-
it 'returns an array of only the required Flag objects' do
89-
expect(subject.required_flags.size).to eq 1
90-
expect(subject.required_flags.first.long).to eq '--force'
97+
it 'returns an array of flags that have a whitelist' do
98+
expect(subject.whitelisted_flags.size).to eq 1
99+
expect(subject.whitelisted_flags.first.long).to eq '--user'
91100
end
92101
end
93102
end

spec/fixtures/script/commands.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,20 @@
199199
help: perform docker container run
200200
parents: [docker, container]
201201

202+
:environment_variable_enthusiast:
203+
name: get
204+
environment_variables:
205+
- name: username
206+
required: true
207+
- name: file
208+
default: README.md
209+
- name: config_dir
210+
validate: dir_exists
211+
- name: protocol
212+
allowed: [ssh, https]
213+
- name: secret
214+
private: true
215+
202216
:examples_array:
203217
name: get
204218
help: get something from somewhere
@@ -404,6 +418,14 @@
404418
alias: cf
405419
private: true
406420

421+
:private_flags:
422+
name: status
423+
help: perform git status
424+
flags:
425+
- long: --legacy
426+
private: true
427+
- long: --new
428+
407429
:repeatable_arg:
408430
name: get
409431
args:

0 commit comments

Comments
 (0)