1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00
fog--fog-aws/tests/helpers/formats_helper_tests.rb
David Bishop 62256219f4 Modernize various tests to Ruby 2.x syntax
Also fix up various things that rubocop called out, though not
everything. Mostly whitespace fixes, changing double-quotes to single if
double wasn't required, changing to use ruby 2.x hash syntax where
possible, etc. While tests don't run, they are no more broken than
before (at least, as far as I can tell).
2018-10-16 16:12:42 -06:00

107 lines
3.5 KiB
Ruby

Shindo.tests('test_helper', 'meta') do
tests('comparing welcome data against schema') do
data = { welcome: 'Hello' }
data_matches_schema(welcome: String) { data }
end
tests('#data_matches_schema') do
tests('when value matches schema expectation') do
data_matches_schema('key' => String) { { 'key' => 'Value' } }
end
tests('when values within an array all match schema expectation') do
data_matches_schema('key' => [Integer]) { { 'key' => [1, 2] } }
end
tests('when nested values match schema expectation') do
data_matches_schema('key' => { nested_key: String }) { { 'key' => { nested_key: 'Value' } } }
end
tests('when collection of values all match schema expectation') do
data_matches_schema([{ 'key' => String }]) { [{ 'key' => 'Value' }, { 'key' => 'Value' }] }
end
tests('when collection is empty although schema covers optional members') do
data_matches_schema([{ 'key' => String }], allow_optional_rules: true) { [] }
end
tests('when additional keys are passed and not strict') do
data_matches_schema({ 'key' => String }, allow_extra_keys: true) { { 'key' => 'Value', extra: 'Bonus' } }
end
tests('when value is nil and schema expects NilClass') do
data_matches_schema('key' => NilClass) { { 'key' => nil } }
end
tests('when value and schema match as hashes') do
data_matches_schema({}) { {} }
end
tests('when value and schema match as arrays') do
data_matches_schema([]) { [] }
end
tests('when value is a Time') do
data_matches_schema('time' => Time) { { 'time' => Time.now } }
end
tests('when key is missing but value should be NilClass (#1477)') do
data_matches_schema({ 'key' => NilClass }, allow_optional_rules: true) { {} }
end
tests('when key is missing but value is nullable (#1477)') do
data_matches_schema({ 'key' => Fog::Nullable::String }, allow_optional_rules: true) { {} }
end
end
tests('#formats backwards compatible changes') do
tests('when value matches schema expectation') do
formats('key' => String) { { 'key' => 'Value' } }
end
tests('when values within an array all match schema expectation') do
formats('key' => [Integer]) { { 'key' => [1, 2] } }
end
tests('when nested values match schema expectation') do
formats('key' => { nested_key: String }) { { 'key' => { nested_key: 'Value' } } }
end
tests('when collection of values all match schema expectation') do
formats([{ 'key' => String }]) { [{ 'key' => 'Value' }, { 'key' => 'Value' }] }
end
tests('when collection is empty although schema covers optional members') do
formats([{ 'key' => String }]) { [] }
end
tests('when additional keys are passed and not strict') do
formats({ 'key' => String }, false) { { 'key' => 'Value', :extra => 'Bonus' } }
end
tests('when value is nil and schema expects NilClass') do
formats('key' => NilClass) { { 'key' => nil } }
end
tests('when value and schema match as hashes') do
formats({}) { {} }
end
tests('when value and schema match as arrays') do
formats([]) { [] }
end
tests('when value is a Time') do
formats('time' => Time) { { 'time' => Time.now } }
end
tests('when key is missing but value should be NilClass (#1477)') do
formats('key' => NilClass) { {} }
end
tests('when key is missing but value is nullable (#1477)') do
formats('key' => Fog::Nullable::String) { {} }
end
end
end