Skip to content

Commit 0fa1828

Browse files
committed
update specs
1 parent c3edf8c commit 0fa1828

File tree

8 files changed

+156
-11
lines changed

8 files changed

+156
-11
lines changed

lib/bashly/concerns/validation_helpers.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,13 @@ def assert_array(key, value, of: nil)
3535
end
3636
end
3737

38-
def assert_hash(key, value, keys: nil, of: nil)
38+
def assert_hash(key, value, keys: nil)
3939
assert value.is_a?(Hash), "#{key} must be a hash"
4040

4141
if keys
4242
invalid_keys = value.keys.map(&:to_sym) - keys
4343
assert invalid_keys.empty?, "#{key} contains invalid options: #{invalid_keys.join ', '}"
4444
end
45-
46-
return unless of
47-
48-
value.each do |k, v|
49-
send "assert_#{of}".to_sym, "#{key}.#{k}", v
50-
end
5145
end
5246

5347
def assert_uniq(key, value, array_keys)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.dependencies.docker.command must be a string or an array>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.dependencies.http_client.help must be a string>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.dependencies.docker contains invalid options: invalid_key>

spec/bashly/script/command_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@
145145
end
146146
end
147147

148+
describe '#dependencies' do
149+
let(:fixture) { :dependencies }
150+
151+
it 'returns an array of Dependency objects' do
152+
expect(subject.dependencies).to be_an Array
153+
expect(subject.dependencies.first).to be_a Script::Dependency
154+
end
155+
end
156+
148157
describe '#environment_cariables' do
149158
it 'returns an array of EnvironemntVariable objects' do
150159
expect(subject.environment_variables).to be_an Array
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
require 'spec_helper'
2+
3+
describe Script::Dependency do
4+
subject do
5+
options = load_fixture('script/commands')[fixture]
6+
Script::Command.new(options).dependencies.first
7+
end
8+
9+
let(:fixture) { :dependencies }
10+
11+
describe '::from_config' do
12+
context 'with an unrecognized configuration' do
13+
it 'returns an empty instahnce' do
14+
expect(described_class.from_config('curl', 1)).to be_a described_class
15+
end
16+
end
17+
end
18+
19+
describe '#label' do
20+
context 'when initialized with a string' do
21+
it 'returns the string' do
22+
expect(subject.label).to eq 'curl'
23+
end
24+
end
25+
26+
context 'when initialized with a command => help hash' do
27+
let(:fixture) { :dependencies_simple_hash }
28+
29+
it 'returns the command' do
30+
expect(subject.label).to eq 'curl'
31+
end
32+
end
33+
34+
context 'when initialized with a label => config hash' do
35+
let(:fixture) { :dependencies_full_hash }
36+
37+
it 'returns the label' do
38+
expect(subject.label).to eq 'http_client'
39+
end
40+
end
41+
end
42+
43+
describe '#commands' do
44+
context 'when initialized with a string' do
45+
it 'returns an array with that string as its only element' do
46+
expect(subject.commands).to eq ['curl']
47+
end
48+
end
49+
50+
context 'when initialized with a command => help hash' do
51+
let(:fixture) { :dependencies_simple_hash }
52+
53+
it 'returns an array with the command as its only element' do
54+
expect(subject.commands).to eq ['curl']
55+
end
56+
end
57+
58+
context 'when initialized with a label => config hash' do
59+
let(:fixture) { :dependencies_full_hash }
60+
61+
it 'returns the commands provided by the config' do
62+
expect(subject.commands).to match_array %w[curl wget]
63+
end
64+
end
65+
end
66+
67+
describe '#help' do
68+
context 'when initialized with a string' do
69+
it 'returns nil' do
70+
expect(subject.help).to be_nil
71+
end
72+
end
73+
74+
context 'when initialized with a command => help hash' do
75+
let(:fixture) { :dependencies_simple_hash }
76+
77+
it 'returns the provided help' do
78+
expect(subject.help).to eq 'Please install curl'
79+
end
80+
end
81+
82+
context 'when initialized with a label => config hash' do
83+
let(:fixture) { :dependencies_full_hash }
84+
85+
it 'returns the help provided by the config' do
86+
expect(subject.help).to eq 'Please install curl or wget'
87+
end
88+
end
89+
end
90+
91+
describe '#name' do
92+
context 'when there is only one command' do
93+
it 'returns it' do
94+
expect(subject.name).to eq 'curl'
95+
end
96+
end
97+
98+
context 'when there are more than one commands' do
99+
let(:fixture) { :dependencies_full_hash }
100+
101+
it 'returns a string suitable for the error message' do
102+
expect(subject.name).to eq 'http_client (curl/wget)'
103+
end
104+
end
105+
end
106+
end

spec/fixtures/script/commands.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,24 @@
166166
arg: format
167167
default: png
168168

169+
:dependencies:
170+
name: cli
171+
dependencies:
172+
- curl
173+
- jq
174+
175+
:dependencies_simple_hash:
176+
name: cli
177+
dependencies:
178+
curl: Please install curl
179+
180+
:dependencies_full_hash:
181+
name: cli
182+
dependencies:
183+
http_client:
184+
command: [curl, wget]
185+
help: Please install curl or wget
186+
169187
:docker:
170188
name: docker
171189
help: run docker commands

spec/fixtures/script/validations.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@
4848
name: invalid
4949
dependencies: 1
5050

51-
:command_dependencies_invalid:
52-
name: invalid
53-
dependencies: 1
54-
5551
:command_dependencies_invalid_array:
5652
name: invalid
5753
dependencies: [1, 2]
@@ -62,6 +58,25 @@
6258
docker: 1
6359
git: 2
6460

61+
:command_dependencies_invalid_hash_command:
62+
name: invalid
63+
dependencies:
64+
docker:
65+
command: 1
66+
67+
:command_dependencies_invalid_hash_help:
68+
name: invalid
69+
dependencies:
70+
http_client:
71+
command: [curl, wget]
72+
help: 1
73+
74+
:command_dependencies_invalid_hash_keys:
75+
name: invalid
76+
dependencies:
77+
docker:
78+
invalid_key: goes here
79+
6580
:command_expose_invalid_type:
6681
name: invalid
6782
help: expose should be boolean or 'always'

0 commit comments

Comments
 (0)