2010-03-28 20:04:38 -04:00
|
|
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'fog'))
|
|
|
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'fog', 'bin'))
|
|
|
|
|
2010-05-06 00:40:21 -04:00
|
|
|
if ENV["FOG_MOCK"] == "true"
|
|
|
|
Fog.mock!
|
|
|
|
end
|
|
|
|
|
2010-05-08 17:51:41 -04:00
|
|
|
def has_error(error, &block)
|
2010-05-06 00:40:21 -04:00
|
|
|
begin
|
|
|
|
yield
|
|
|
|
@formatador.display_line("[red]did not raise #{error}[/]")
|
|
|
|
false
|
|
|
|
rescue error
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-05-08 17:51:41 -04:00
|
|
|
def has_format(original_data, original_format)
|
2010-03-28 20:04:38 -04:00
|
|
|
valid = true
|
|
|
|
data = original_data.dup
|
2010-05-08 17:51:41 -04:00
|
|
|
format = original_format.dup
|
2010-03-28 20:04:38 -04:00
|
|
|
for key, value in format
|
|
|
|
valid &&= data.has_key?(key)
|
|
|
|
datum = data.delete(key)
|
2010-05-08 17:51:41 -04:00
|
|
|
format.delete(key)
|
2010-03-28 20:04:38 -04:00
|
|
|
case value
|
|
|
|
when Array
|
|
|
|
valid &&= datum.is_a?(Array)
|
|
|
|
for element in datum
|
|
|
|
type = value.first
|
|
|
|
if type.is_a?(Hash)
|
2010-05-06 00:40:21 -04:00
|
|
|
valid &&= has_format({:element => element}, {:element => type})
|
2010-03-28 20:04:38 -04:00
|
|
|
else
|
|
|
|
valid &&= element.is_a?(type)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
when Hash
|
|
|
|
valid &&= datum.is_a?(Hash)
|
2010-05-06 00:40:21 -04:00
|
|
|
valid &&= has_format(datum, value)
|
2010-03-28 20:04:38 -04:00
|
|
|
else
|
|
|
|
valid &&= datum.is_a?(value)
|
|
|
|
end
|
|
|
|
end
|
2010-05-08 17:51:41 -04:00
|
|
|
valid &&= data.empty? && format.empty?
|
2010-04-05 01:11:28 -04:00
|
|
|
unless valid
|
2010-05-08 17:51:41 -04:00
|
|
|
@formatador.display_line("[red]#{original_data.inspect} does not match #{original_format.inspect}[/]")
|
2010-04-05 01:11:28 -04:00
|
|
|
end
|
|
|
|
valid
|
2010-03-28 20:04:38 -04:00
|
|
|
end
|