2010-04-05 01:11:28 -04:00
|
|
|
Shindo.tests('test_helper', 'meta') do
|
2010-05-06 00:40:21 -04:00
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
tests('comparing welcome data against schema') do
|
|
|
|
data = {:welcome => "Hello" }
|
|
|
|
data_matches_schema(:welcome => String) { data }
|
|
|
|
end
|
2013-01-22 05:45:23 -05:00
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
tests('#data_matches_schema') do
|
2013-01-22 05:45:23 -05:00
|
|
|
tests('when value matches schema expectation') do
|
2013-01-23 06:27:14 -05:00
|
|
|
data_matches_schema({"key" => String}) { {"key" => "Value"} }
|
2013-01-22 05:45:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('when values within an array all match schema expectation') do
|
2013-01-23 06:27:14 -05:00
|
|
|
data_matches_schema({"key" => [Integer]}) { {"key" => [1, 2]} }
|
2013-01-22 05:45:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('when nested values match schema expectation') do
|
2013-01-23 06:27:14 -05:00
|
|
|
data_matches_schema({"key" => {:nested_key => String}}) { {"key" => {:nested_key => "Value"}} }
|
2013-01-22 05:45:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('when collection of values all match schema expectation') do
|
2013-01-23 06:27:14 -05:00
|
|
|
data_matches_schema([{"key" => String}]) { [{"key" => "Value"}, {"key" => "Value"}] }
|
2013-01-22 05:45:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('when collection is empty although schema covers optional members') do
|
2013-01-23 06:27:14 -05:00
|
|
|
data_matches_schema([{"key" => String}], {:allow_optional_rules => true}) { [] }
|
2013-01-22 05:45:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('when additional keys are passed and not strict') do
|
2013-01-23 06:27:14 -05:00
|
|
|
data_matches_schema({"key" => String}, {:allow_extra_keys => true}) { {"key" => "Value", :extra => "Bonus"} }
|
2013-01-22 05:45:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('when value is nil and schema expects NilClass') do
|
2013-01-23 06:27:14 -05:00
|
|
|
data_matches_schema({"key" => NilClass}) { {"key" => nil} }
|
2013-01-22 05:45:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('when value and schema match as hashes') do
|
2013-01-23 06:27:14 -05:00
|
|
|
data_matches_schema({}) { {} }
|
2013-01-22 05:45:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('when value and schema match as arrays') do
|
2013-01-23 06:27:14 -05:00
|
|
|
data_matches_schema([]) { [] }
|
2013-01-22 05:45:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('when value is a Time') do
|
2013-01-23 06:27:14 -05:00
|
|
|
data_matches_schema({"time" => Time}) { {"time" => Time.now} }
|
2013-01-22 05:45:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('when key is missing but value should be NilClass (#1477)') do
|
2013-01-23 06:27:14 -05:00
|
|
|
data_matches_schema({"key" => NilClass}, {:allow_optional_rules => true}) { {} }
|
2013-01-22 05:45:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('when key is missing but value is nullable (#1477)') do
|
2013-01-23 06:27:14 -05:00
|
|
|
data_matches_schema({"key" => Fog::Nullable::String}, {:allow_optional_rules => true}) { {} }
|
2013-01-22 05:45:23 -05:00
|
|
|
end
|
2013-01-16 10:44:56 -05:00
|
|
|
end
|
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
tests('#formats backwards compatible changes') do
|
2011-09-28 15:24:40 -04:00
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
tests('when value matches schema expectation') do
|
|
|
|
formats({"key" => String}) { {"key" => "Value"} }
|
2010-03-28 20:04:38 -04:00
|
|
|
end
|
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
tests('when values within an array all match schema expectation') do
|
|
|
|
formats({"key" => [Integer]}) { {"key" => [1, 2]} }
|
|
|
|
end
|
2010-03-28 20:04:38 -04:00
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
tests('when nested values match schema expectation') do
|
|
|
|
formats({"key" => {:nested_key => String}}) { {"key" => {:nested_key => "Value"}} }
|
|
|
|
end
|
2010-03-28 20:04:38 -04:00
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
tests('when collection of values all match schema expectation') do
|
|
|
|
formats([{"key" => String}]) { [{"key" => "Value"}, {"key" => "Value"}] }
|
|
|
|
end
|
2010-03-28 20:04:38 -04:00
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
tests('when collection is empty although schema covers optional members') do
|
|
|
|
formats([{"key" => String}]) { [] }
|
|
|
|
end
|
2012-09-04 16:23:04 -04:00
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
tests('when additional keys are passed and not strict') do
|
|
|
|
formats({"key" => String}, false) { {"key" => "Value", :extra => "Bonus"} }
|
|
|
|
end
|
2012-09-04 16:23:04 -04:00
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
tests('when value is nil and schema expects NilClass') do
|
|
|
|
formats({"key" => NilClass}) { {"key" => nil} }
|
|
|
|
end
|
2013-01-22 05:45:23 -05:00
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
tests('when value and schema match as hashes') do
|
|
|
|
formats({}) { {} }
|
|
|
|
end
|
2012-09-04 16:23:04 -04:00
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
tests('when value and schema match as arrays') do
|
|
|
|
formats([]) { [] }
|
|
|
|
end
|
2013-01-16 10:44:56 -05:00
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
tests('when value is a Time') do
|
|
|
|
formats({"time" => Time}) { {"time" => Time.now} }
|
|
|
|
end
|
2013-01-16 10:44:56 -05:00
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
tests('when key is missing but value should be NilClass (#1477)') do
|
|
|
|
formats({"key" => NilClass}) { {} }
|
|
|
|
end
|
2011-09-28 15:24:40 -04:00
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
tests('when key is missing but value is nullable (#1477)') do
|
|
|
|
formats({"key" => Fog::Nullable::String}) { {} }
|
2010-03-28 20:04:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2010-05-06 00:40:21 -04:00
|
|
|
|
2013-01-23 06:27:14 -05:00
|
|
|
|
2010-03-28 20:04:38 -04:00
|
|
|
end
|