spec/lib/pact/matchers/matchers_spec.rb in pact-1.0.7 vs spec/lib/pact/matchers/matchers_spec.rb in pact-1.0.8

- old
+ new

@@ -1,12 +1,27 @@ require 'spec_helper' require 'pact/term' +require 'pact/something_like' require 'pact/matchers' describe Pact::Matchers do include Pact::Matchers + describe 'matching with something like' do + + context 'when the actual is something like the expected' do + let(:expected) { Pact::SomethingLike.new( { a: 1 } ) } + let(:actual) { { a: 2} } + + it 'returns an empty diff' do + expect(diff(expected, actual)).to eq({}) + end + + end + + end + describe 'option {allow_unexpected_keys: false}' do context "when an unexpected key is found" do let(:expected) { {:a => 1} } let(:actual) { {:a => 1, :b => 2} } let(:difference) { {:b => {:expected => '<key not to be present>', :actual => 2 }} } @@ -312,22 +327,22 @@ expect(diff(subject, actual)).to eql(difference) end end context "a deep mismatch" do - subject { {a: {b: { c: [1,2]}, d: { e: Pact::Term.new(matcher: /a/)}}, f: 1, g: {h: 99}} } + subject { {a: {b: { c: [1,2]}, d: { e: Pact::Term.new(matcher: /a/, generate: 'apple')}}, f: 1, g: {h: 99}} } let(:actual) { {a: {b: { c: [1,2]}, d: { e: 'food'}}, f: "thing"} } let(:difference) { {:a=>{:d=>{:e=>{:expected=>/a/, :actual=>"food"}}}, :f=>{:expected=>1, :actual=>"thing"}, :g=>{:expected=>{:h=>99}, :actual=> Pact::Matchers::KeyNotFound.new}} } it 'should return the diff' do expect(diff(subject, actual)).to eql(difference) end end context "where a Pact::Term is found that matches the actual value" do - subject { {:a => Pact::Term.new(:matcher => /a/)} } + subject { {:a => Pact::Term.new(:matcher => /a/, :generate => 'apple')} } let(:actual) { {:a => "apple" } } it 'does not include this in the diff' do expect(diff(subject, actual)).to eql({}) end @@ -369,10 +384,10 @@ expect(diff(subject, actual)).to eql(difference) end end context "when an array that matches the Pact::Term is found" do - subject { [Pact::Term.new(:matcher => /4/),"5","6"] } + subject { [Pact::Term.new(:matcher => /4/, :generate => '4'),"5","6"] } let(:actual) { ["4","5","6"] } it 'includes this in the diff' do expect(diff(subject, actual)).to eql({}) end \ No newline at end of file