lib/service_contract/assertions.rb in service_contract-0.0.6 vs lib/service_contract/assertions.rb in service_contract-0.0.7
- old
+ new
@@ -11,22 +11,35 @@
data.each do |datum|
assert_data_matches_type(datum, type.subtype)
end
else
type.fields.each do |field|
- assert data.has_key?(field.name), "expected #{type.name} to have attribute: #{field.name}"
- value = data.fetch(field.name)
+ value = data.fetch(field.name) do
+ data.fetch(field.name.to_sym) do
+ assert false, "expected #{type.name} to have attribute: #{field.name}"
+ end
+ end
expected_classes = classes_for_parameter(field)
assert (allow_nil && value.nil?) || expected_classes.any?{|klass| value.is_a?(klass)}, "expected #{type.name}.#{field.name} to be a #{expected_classes.join(", ")}"
+
+ if field.type == "array"
+ value.each do |val|
+ assert_data_matches_type(val, field.subtype)
+ end
+ end
end
end
end
protected
def classes_for_parameter(field)
- classes = case field.type
+ type = field.type
+ type = type.type_sym.to_s if type.respond_to?(:type_sym)
+ classes = case type
+ when "array"
+ Array
when "int"
Fixnum
when "string"
String
when "float"
\ No newline at end of file