lib/airborne/request_expectations.rb in airborne-0.2.0 vs lib/airborne/request_expectations.rb in airborne-0.2.1

- old
+ new

@@ -83,11 +83,11 @@ keys << expected.keys if match_expected? keys << actual.keys if match_actual? keys = expected.keys & actual.keys if match_none? keys.flatten.uniq.each do |prop| - expected_value = extract_expected(expected, prop) + expected_value = extract_expected_value(expected, prop) actual_value = extract_actual(actual, prop) next expect_json_impl(expected_value, actual_value) if hash?(expected_value) next expected_value.call(actual_value) if expected_value.is_a?(Proc) next expect(actual_value.to_s).to match(expected_value) if expected_value.is_a?(Regexp) @@ -111,11 +111,11 @@ keys << expected.keys if match_expected? keys << actual.keys if match_actual? keys = expected.keys & actual.keys if match_none? keys.flatten.uniq.each do |prop| - type = extract_expected(expected, prop) + type = extract_expected_type(expected, prop) value = extract_actual(actual, prop) value = convert_to_date(value) if type == :date next expect_json_types_impl(type, value) if hash?(type) next type.call(value) if type.is_a?(Proc) @@ -138,10 +138,19 @@ else yield(args[0], json_body) end end - def extract_expected(expected, prop) + def extract_expected_value(expected, prop) + begin + raise unless expected.keys.include?(prop) + expected[prop] + rescue + raise ExpectationError, "Expectation is expected to contain property: #{prop}" + end + end + + def extract_expected_type(expected, prop) begin type = expected[prop] type.nil? ? raise : type rescue raise ExpectationError, "Expectation is expected to contain property: #{prop}"