diff --git a/tests/helper.rb b/tests/helper.rb index 6c2213143..11c7c84cb 100644 --- a/tests/helper.rb +++ b/tests/helper.rb @@ -17,92 +17,6 @@ for provider in (all_providers - available_providers) Thread.current[:tags] << ('-' << provider) end -# format related hackery -# allows both true.is_a?(Fog::Boolean) and false.is_a?(Fog::Boolean) -# allows both nil.is_a?(Fog::Nullable::String) and ''.is_a?(Fog::Nullable::String) -module Fog - module Boolean; end - module Nullable - module String; end - end -end - -[FalseClass, TrueClass].each {|klass| klass.send(:include, Fog::Boolean)} -[NilClass, String].each {|klass| klass.send(:include, Fog::String)} - def lorem_file File.open(File.dirname(__FILE__) + '/lorem.txt', 'r') end - -module Shindo - class Tests - - def responds_to(method_names) - for method_name in [*method_names] - tests("#respond_to?(:#{method_name})").succeeds do - @instance.respond_to?(method_name) - end - end - end - - def formats(format) - test('has proper format') do - formats_kernel(instance_eval(&Proc.new), format) - end - end - - def succeeds - test('succeeds') do - instance_eval(&Proc.new) - true - end - end - - private - - def formats_kernel(original_data, original_format, original = true) - valid = true - data = original_data.dup - format = original_format.dup - if format.is_a?(Array) - data = {:element => data} - format = {:element => format} - end - 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 - end - end - when Hash - valid &&= datum.is_a?(Hash) - valid &&= formats_kernel(datum, value, false) - else - p "#{key} => #{value}" unless datum.is_a?(value) - valid &&= datum.is_a?(value) - end - end - p data unless data.empty? - p format unless format.empty? - valid &&= data.empty? && format.empty? - if !valid && original - @message = "#{original_data.inspect} does not match #{original_format.inspect}" - end - valid - end - - end -end diff --git a/tests/helpers/formats_helper.rb b/tests/helpers/formats_helper.rb new file mode 100644 index 000000000..fe7776ef8 --- /dev/null +++ b/tests/helpers/formats_helper.rb @@ -0,0 +1,69 @@ +# format related hackery +# allows both true.is_a?(Fog::Boolean) and false.is_a?(Fog::Boolean) +# allows both nil.is_a?(Fog::Nullable::String) and ''.is_a?(Fog::Nullable::String) +module Fog + module Boolean; end + module Nullable + module String; end + end +end +[FalseClass, TrueClass].each {|klass| klass.send(:include, Fog::Boolean)} +[NilClass, String].each {|klass| klass.send(:include, Fog::String)} + +module Shindo + class Tests + + def formats(format) + test('has proper format') do + formats_kernel(instance_eval(&Proc.new), format) + end + end + + private + + def formats_kernel(original_data, original_format, original = true) + valid = true + data = original_data.dup + format = original_format.dup + if format.is_a?(Array) + data = {:element => data} + format = {:element => format} + end + 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 + end + end + when Hash + valid &&= datum.is_a?(Hash) + valid &&= formats_kernel(datum, value, false) + else + p "#{key} => #{value}" unless datum.is_a?(value) + valid &&= datum.is_a?(value) + end + end + p data unless data.empty? + p format unless format.empty? + valid &&= data.empty? && format.empty? + if !valid && original + @message = "#{original_data.inspect} does not match #{original_format.inspect}" + end + valid + end + + end +end diff --git a/tests/helper_tests.rb b/tests/helpers/formats_helper_tests.rb similarity index 100% rename from tests/helper_tests.rb rename to tests/helpers/formats_helper_tests.rb diff --git a/tests/helpers/responds_to_helper.rb b/tests/helpers/responds_to_helper.rb new file mode 100644 index 000000000..5a4127a5f --- /dev/null +++ b/tests/helpers/responds_to_helper.rb @@ -0,0 +1,13 @@ +module Shindo + class Tests + + def responds_to(method_names) + for method_name in [*method_names] + tests("#respond_to?(:#{method_name})").succeeds do + @instance.respond_to?(method_name) + end + end + end + + end +end \ No newline at end of file diff --git a/tests/helpers/succeeds_helper.rb b/tests/helpers/succeeds_helper.rb new file mode 100644 index 000000000..527a06735 --- /dev/null +++ b/tests/helpers/succeeds_helper.rb @@ -0,0 +1,12 @@ +module Shindo + class Tests + + def succeeds + test('succeeds') do + instance_eval(&Proc.new) + true + end + end + + end +end \ No newline at end of file