Skip to content

Commit

Permalink
add specs for LibrarySourceConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed Oct 18, 2023
1 parent a44cbde commit b52dc92
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/bashly/library_source_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def assert_root(path, value)

def assert_lib(key, value)
assert_string "#{key}.help", value['help']

assert_optional_string "#{key}.usage", value['usage']
assert_optional_string "#{key}.handler", value['handler']
assert_optional_string "#{key}.post_install_message", value['post_install_message']
Expand Down
1 change: 1 addition & 0 deletions spec/approvals/libraries_validation/files_array
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: [spec/fixtures/libraries/errors/files_array.yml] database.files must be an array>
1 change: 1 addition & 0 deletions spec/approvals/libraries_validation/files_source
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: [spec/fixtures/libraries/errors/files_source.yml] database.files[0].source must be a string>
1 change: 1 addition & 0 deletions spec/approvals/libraries_validation/files_target
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: [spec/fixtures/libraries/errors/files_target.yml] database.files[0].target must be a string>
1 change: 1 addition & 0 deletions spec/approvals/libraries_validation/handler_string
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: [spec/fixtures/libraries/errors/handler_string.yml] database.handler must be a string>
1 change: 1 addition & 0 deletions spec/approvals/libraries_validation/help_string
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: [spec/fixtures/libraries/errors/help_string.yml] database.help must be a string>
1 change: 1 addition & 0 deletions spec/approvals/libraries_validation/message_string
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: [spec/fixtures/libraries/errors/message_string.yml] database.post_install_message must be a string>
1 change: 1 addition & 0 deletions spec/approvals/libraries_validation/root_hash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: spec/fixtures/libraries/errors/root_hash.yml must be a hash>
1 change: 1 addition & 0 deletions spec/approvals/libraries_validation/usage_string
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: [spec/fixtures/libraries/errors/usage_string.yml] database.usage must be a string>
7 changes: 3 additions & 4 deletions spec/bashly/config_validator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
describe ConfigValidator do
fixtures = load_fixture 'script/validations'
subject { described_class.new options }

describe '#validate' do
fixtures.each do |fixture, options|
context "with :#{fixture}" do
let(:options) { options }
validator = described_class.new options

context "with :#{fixture}" do
it 'raises an error' do
expect { subject.validate }.to raise_approval("validations/#{fixture}")
expect { validator.validate }.to raise_approval("validations/#{fixture}")
end
end
end
Expand Down
26 changes: 26 additions & 0 deletions spec/bashly/library_source_config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
describe LibrarySourceConfig do
fixtures = Dir['spec/fixtures/libraries_errors/*.yml']
subject { described_class.new path }

let(:path) { 'spec/fixtures/libraries/libraries.yml' }

describe '#validated_data' do
it 'returns the data after validating it' do
expect(subject).to receive(:validate)
expect(subject.validated_data).to eq subject.data
end
end

describe '#validate' do
fixtures.each do |path|
fixture_name = File.basename path, '.yml'
config = described_class.new path

context "with #{fixture_name}.yml" do
it 'raises an error' do
expect { config.validate }.to raise_approval("libraries_validation/#{fixture_name}")
end
end
end
end
end
4 changes: 4 additions & 0 deletions spec/fixtures/libraries_validation/files_array.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# error: files must be an array
database:
help: Help text
files: one_file.txt
6 changes: 6 additions & 0 deletions spec/fixtures/libraries_validation/files_source.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# error: files must have a source
database:
help: Help text
files:
- target: some_target

6 changes: 6 additions & 0 deletions spec/fixtures/libraries_validation/files_target.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# error: files must have a target
database:
help: Help text
files:
- source: some_source

7 changes: 7 additions & 0 deletions spec/fixtures/libraries_validation/handler_string.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# error: handler must be a string (optional)
database:
help: Help text
handler: 1
files:
- source: "database/database.sh"
target: "%{user_lib_dir}/database.%{user_ext}"
6 changes: 6 additions & 0 deletions spec/fixtures/libraries_validation/help_string.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# error: help must be a string
database:
help: 1
files:
- source: "database/database.sh"
target: "%{user_lib_dir}/database.%{user_ext}"
7 changes: 7 additions & 0 deletions spec/fixtures/libraries_validation/message_string.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# error: post_install_message must be a string (optional)
database:
help: Help text
post_install_message: 1
files:
- source: "database/database.sh"
target: "%{user_lib_dir}/database.%{user_ext}"
6 changes: 6 additions & 0 deletions spec/fixtures/libraries_validation/root_hash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# error: must be a hash
- database:
help: Add database utilities
files:
- source: "database/database.sh"
target: "%{user_lib_dir}/database.%{user_ext}"
7 changes: 7 additions & 0 deletions spec/fixtures/libraries_validation/usage_string.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# error: usage must be a string (optional)
database:
help: Help text
usage: 1
files:
- source: "database/database.sh"
target: "%{user_lib_dir}/database.%{user_ext}"

0 comments on commit b52dc92

Please sign in to comment.