1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/tests/helper.rb

91 lines
2.4 KiB
Ruby
Raw Normal View History

2010-09-23 13:48:52 -04:00
require 'fog'
require 'fog/core/bin'
2010-09-23 13:48:52 -04:00
Fog.bin = true
require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'model_helper'))
require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'storage', 'directory_tests'))
require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'storage', 'directories_tests'))
require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'storage', 'file_tests'))
require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'storage', 'files_tests'))
if ENV["FOG_MOCK"] == "true"
Fog.mock!
end
# Boolean hax
module Fog
module Boolean
end
end
FalseClass.send(:include, Fog::Boolean)
TrueClass.send(:include, Fog::Boolean)
def lorem_file
File.open(File.dirname(__FILE__) + '/lorem.txt', 'r')
end
2010-05-21 17:43:29 -04:00
module Shindo
class Tests
2010-05-21 17:43:29 -04:00
def formats(format, &block)
test('has proper format') do
formats_kernel(instance_eval(&block), format)
end
end
def succeeds(&block)
test('succeeds') do
2010-05-31 11:37:26 -04:00
instance_eval(&block)
true
2010-05-21 17:43:29 -04:00
end
end
private
def formats_kernel(original_data, original_format, original = true)
valid = true
data = original_data.dup
format = original_format.dup
2010-06-04 00:32:59 -04:00
if format.is_a?(Array)
data = {:element => data}
format = {:element => format}
end
2010-05-21 17:43:29 -04:00
for key, value in format
valid &&= data.has_key?(key)
datum = data.delete(key)
format.delete(key)
case value
when Array
valid &&= datum.is_a?(Array)
if datum.is_a?(Array)
for element in datum
type = value.first
if type.is_a?(Hash)
valid &&= formats_kernel({:element => element}, {:element => type}, false)
elsif type.nil?
p "#{key} => #{value}"
else
valid &&= element.is_a?(type)
end
2010-05-21 17:43:29 -04:00
end
end
when Hash
valid &&= datum.is_a?(Hash)
valid &&= formats_kernel(datum, value, false)
else
p "#{key} => #{value}" unless datum.is_a?(value)
2010-05-21 17:43:29 -04:00
valid &&= datum.is_a?(value)
end
end
p data unless data.empty?
p format unless format.empty?
2010-05-21 17:43:29 -04:00
valid &&= data.empty? && format.empty?
if !valid && original
@message = "#{original_data.inspect} does not match #{original_format.inspect}"
end
valid
end
2010-05-21 17:43:29 -04:00
end
end