lib/airborne/request_expectations.rb in airborne-0.0.16 vs lib/airborne/request_expectations.rb in airborne-0.0.17

- old
+ new

@@ -45,10 +45,14 @@ else raise "Header #{key} not present in HTTP response" end end + def optional(hash) + OptionalHashTypeExpectations.new(hash) + end + private def call_with_path(args) if args.length == 2 get_by_path(args[0], json_body) do|json_chunk| @@ -85,13 +89,14 @@ end mapper end def expect_json_types_impl(expectations, hash) + return if expectations.class == Airborne::OptionalHashTypeExpectations && hash.nil? @mapper ||= get_mapper expectations.each do |prop_name, expected_type| value = hash[prop_name] - if expected_type.class == Hash + if expected_type.class == Hash || expected_type.class == Airborne::OptionalHashTypeExpectations expect_json_types_impl(expected_type, value) elsif expected_type.to_s.include?("array_of") expect(value.class).to eq(Array), "Expected #{prop_name} to be of type #{expected_type}, got #{value.class} instead" value.each do |val| expect(@mapper[expected_type].include?(val.class)).to eq(true), "Expected #{prop_name} to be of type #{expected_type}, got #{val.class} instead" \ No newline at end of file