require 'spec_helper' require 'pact/matchers' require 'pact/consumer_contract/headers' module Pact::Matchers describe Pact::Matchers do include Pact::Matchers describe "diff" do STRING = "foo" INT = 1 FLOAT = 1.0 HASH = {foo: "bar"} ARRAY = ["foo"] COMBINATIONS = [ [STRING, "bar", "Expected \"foo\" but got \"bar\" at "], [STRING, nil, "Expected \"foo\" but got nil at "], [STRING, INT, "Expected \"foo\" but got 1 at "], [STRING, FLOAT, "Expected \"foo\" but got 1.0 at "], [STRING, HASH, "Expected \"foo\" but got a Hash at "], [STRING, ARRAY, "Expected \"foo\" but got an Array at "], [Pact.like(STRING), "bar", nil], [Pact.like(STRING), nil, "Expected a String (like \"foo\") but got nil at "], [Pact.like(STRING), INT, "Expected a String (like \"foo\") but got a Fixnum (1) at "], [Pact.like(STRING), FLOAT, "Expected a String (like \"foo\") but got a Float (1.0) at "], [Pact.like(STRING), HASH, "Expected a String (like \"foo\") but got a Hash at "], [Pact.like(STRING), ARRAY, "Expected a String (like \"foo\") but got an Array at "], [INT, 2, "Expected 1 but got 2 at "], [INT, nil, "Expected 1 but got nil at "], [INT, STRING, "Expected 1 but got \"foo\" at "], [INT, FLOAT, "Expected 1 but got \"foo\" at ", {pending: true}], [INT, HASH, "Expected 1 but got a Hash at "], [INT, ARRAY, "Expected 1 but got an Array at "], [Pact.like(INT), 2, nil], [Pact.like(INT), nil, "Expected a Fixnum (like 1) but got nil at "], [Pact.like(INT), STRING, "Expected a Fixnum (like 1) but got a String (\"foo\") at "], [Pact.like(INT), FLOAT, "Expected a Fixnum (like 1) but got a Float (1.0) at "], [Pact.like(INT), HASH, "Expected a Fixnum (like 1) but got a Hash at "], [Pact.like(INT), ARRAY, "Expected a Fixnum (like 1) but got an Array at "], [HASH, HASH, nil], [HASH, nil, "Expected a Hash but got nil at "], [HASH, STRING, "Expected a Hash but got a String (\"foo\") at "], [HASH, INT, "Expected a Hash but got a Fixnum (1) at "], [HASH, FLOAT, "Expected a Hash but got a Float (1.0) at "], [HASH, ARRAY, "Expected a Hash but got an Array at "], [Pact.like(HASH), STRING, "Expected a Hash but got a String (\"foo\") at "], [ARRAY, ARRAY, nil], [ARRAY, nil, "Expected an Array but got nil at "], [ARRAY, STRING, "Expected an Array but got a String (\"foo\") at "], [ARRAY, INT, "Expected an Array but got a Fixnum (1) at "], [ARRAY, FLOAT, "Expected an Array but got a Float (1.0) at "], [ARRAY, HASH, "Expected an Array but got a Hash at "] ] COMBINATIONS.each do | expected, actual, expected_message, options | context "when expected is #{expected.inspect} and actual is #{actual.inspect}", options || {} do let(:difference) { diff({thing: expected}, {thing: actual}) } let(:message) { difference[:thing] ? difference[:thing].message : nil } it "returns the message '#{expected_message}'" do expect(message).to eq expected_message end end end end end end