lib/enumeration/assert_macros.rb in enumeration-1.3.1 vs lib/enumeration/assert_macros.rb in enumeration-1.3.2
- old
+ new
@@ -1,56 +1,59 @@
-module Enumeration; end
-module Enumeration::AssertMacros
+module Enumeration
- # a set of Assert macros to help write enum definition and
- # regression tests in Assert (https://github.com/teaminsight/assert)
+ module AssertMacros
- def self.included(receiver)
- receiver.class_eval do
- extend MacroMethods
- end
- end
+ # a set of Assert macros to help write enum definition and
+ # regression tests in Assert (https://github.com/teaminsight/assert)
- module MacroMethods
-
- def have_enum(name, *args)
- values = [*args].flatten
- type = nil
- if values.first.kind_of?(::Hash)
- values = values.first
- type = 'map'
- elsif !values.empty?
- type = 'list'
+ def self.included(receiver)
+ receiver.class_eval do
+ extend MacroMethods
end
+ end
- called_from = caller.first
- macro_name = "have the"
- macro_name += " #{type}" if type
- macro_name += " enum '#{name}'"
- macro_name += " with #{values.inspect} values" if !values.empty?
+ module MacroMethods
- Assert::Macro.new(macro_name) do
- should have_accessor name, [called_from]
+ def have_enum(name, *args)
+ values = [*args].flatten
+ type = nil
+ if values.first.kind_of?(::Hash)
+ values = values.first
+ type = 'map'
+ elsif !values.empty?
+ type = 'list'
+ end
- should have_class_method "#{name}_collection", [called_from]
+ called_from = caller.first
+ macro_name = "have the"
+ macro_name += " #{type}" if type
+ macro_name += " enum '#{name}'"
+ macro_name += " with #{values.inspect} values" if !values.empty?
- if type == 'map'
- should have_class_method name, [called_from]
- end
+ Assert::Macro.new(macro_name) do
+ should have_accessor name, [called_from]
- if !values.empty?
- should "know its '#{name}' enum values", called_from do
- assert_equal values, subject.class.send("#{name}_collection")
- end
+ should have_class_method "#{name}_collection", [called_from]
if type == 'map'
- should "map the '#{name}' enum values at the class level", called_from do
- values.each {|k,v| assert_equal v, subject.class.send(name, k)}
+ should have_class_method name, [called_from]
+ end
+
+ if !values.empty?
+ should "know its '#{name}' enum values", called_from do
+ assert_equal values, subject.class.send("#{name}_collection")
end
+
+ if type == 'map'
+ should "map the '#{name}' enum values at the class level", called_from do
+ values.each {|k,v| assert_equal v, subject.class.send(name, k)}
+ end
+ end
end
- end
+ end
end
+
end
end
end