Sha256: 8525c2ff44ddfdc0e0ed60043ffd08cd2955350e361af1fabb997c73e895b311

Contents?: true

Size: 1.68 KB

Versions: 3

Compression:

Stored size: 1.68 KB

Contents

require 'pact/provider/rspec'
require 'pact/provider/rspec/matchers'

describe "the match_term matcher" do

  include Pact::RSpec::Matchers

  it 'does not match a hash to an array' do
    expect({}).to_not match_term([])
  end

  it 'does not match an array to a hash' do
    expect([]).to_not match_term({})
  end

  it 'matches regular expressions' do
    expect('blah').to match_term(/[a-z]*/)
  end

  it 'matches pact terms' do
    expect('wootle').to match_term Pact::Term.new(generate:'wootle', matcher:/woot../)
  end

  it 'matches all elements of arrays' do
    expect(['one', 'two', ['three']]).to match_term [/one/, 'two', [Pact::Term.new(generate:'three', matcher:/thr../)]]
  end

  it 'matches all values of hashes' do
    expect({1 => 'one', 2 => 2, 3 => 'three'}).to match_term({1 => /one/, 2 => 2, 3 => Pact::Term.new(generate:'three', matcher:/thr../)})
  end

  it 'matches all other objects using ==' do
    expect('wootle').to match_term 'wootle'
  end

  # Note: because a consumer specifies only the keys it cares about, the pact ignores keys that are returned
  # by the provider, but not are not specified in the pact. This means that any hash will match an
  # expected empty hash, because there is currently no way for a consumer to expect an absence of keys.
  it 'is confused by an empty hash' do
    expect({:hello => 'everyone'}).to match_term({})
  end

  it 'should not be confused by an empty array' do
    expect(['blah']).to_not match_term([])
  end

  it "should allow matches on an array where each item in the array only contains a subset of the actual" do
    expect([{name: 'Fred', age: 12}, {name: 'John', age: 13}]).to match_term([{name: 'Fred'}, {name: 'John'}])
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pact-1.3.0 spec/lib/pact/provider/rspec_spec.rb
pact-1.2.1.rc2 spec/lib/pact/provider/rspec_spec.rb
pact-1.2.1.rc1 spec/lib/pact/provider/rspec_spec.rb