mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[Core] fix format_helper assuming p returns nil
on ruby 1.9 it returns the printed string so x = foo || p("foo was false") always evaluates to something truthy
This commit is contained in:
parent
66038db5cb
commit
519efbf179
2 changed files with 13 additions and 2 deletions
|
@ -48,7 +48,8 @@ module Shindo
|
|||
format.delete(key)
|
||||
case value
|
||||
when Array
|
||||
valid &&= datum.is_a?(Array) || p("#{key.inspect} not Array: #{datum.inspect}")
|
||||
p("#{key.inspect} not Array: #{datum.inspect}") unless datum.is_a?(Array)
|
||||
valid &&= datum.is_a?(Array)
|
||||
if datum.is_a?(Array) && !value.empty?
|
||||
for element in datum
|
||||
type = value.first
|
||||
|
@ -60,7 +61,8 @@ module Shindo
|
|||
end
|
||||
end
|
||||
when Hash
|
||||
valid &&= datum.is_a?(Hash) || p("#{key.inspect} not Hash: #{datum.inspect}")
|
||||
p("#{key.inspect} not Hash: #{datum.inspect}") unless datum.is_a?(Hash)
|
||||
valid &&= datum.is_a?(Hash)
|
||||
valid &&= formats_kernel(datum, value, false, strict)
|
||||
else
|
||||
p "#{key.inspect} not #{value.inspect}: #{datum.inspect}" unless datum.is_a?(value)
|
||||
|
|
|
@ -40,6 +40,15 @@ Shindo.tests('test_helper', 'meta') do
|
|||
!formats_kernel({}, {:a => String})
|
||||
end
|
||||
|
||||
test('when an array is expected but another data type is found') do
|
||||
!formats_kernel({:a => 'not an array'}, {:a => []})
|
||||
end
|
||||
|
||||
test('when a hash is expected but another data type is found') do
|
||||
!formats_kernel({:a => 'not a hash'}, {:a => {}}, true, false)
|
||||
end
|
||||
|
||||
|
||||
test('non strict extra data') do
|
||||
!formats_kernel({:a => :b, :b => :c}, {:z => Symbol}, true, false)
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue