Sha256: 108e080b51bc5e5c3ae2bb2c741e5c32d02f279225afea91e5e6a7beb0991725

Contents?: true

Size: 754 Bytes

Versions: 100

Compression:

Stored size: 754 Bytes

Contents

# checks if actual contains all the key-value pairs that expected does,
# ignoring order for any child arrays
RSpec::Matchers.define :contain_hash do |expected|
  match do |actual|
    contains_hash?(expected, actual)
  end

  failure_message do |actual|
    "expected #{actual.class} to include #{expected.class}\n" + formatted_diffs
  end

  def formatted_diffs
    @diffs.collect{ | diff| Pact::Matchers::UnixDiffFormatter.call(diff) }.join("\n")
  end

  def contains_hash?(expected, actual)
    if actual.is_a?(Array)
      actual.any? && actual.any?{|actual_item| contains_hash?(expected, actual_item)}
    else
      @diffs ||= []
      diff = Pact::Matchers.diff(expected, actual.to_hash)
      @diffs << diff
      diff.empty?
    end
  end
end

Version data entries

100 entries across 100 versions & 1 rubygems

Version Path
pact_broker-2.89.1 spec/support/rspec_match_hash.rb
pact_broker-2.89.0 spec/support/rspec_match_hash.rb
pact_broker-2.88.0 spec/support/rspec_match_hash.rb
pact_broker-2.87.0 spec/support/rspec_match_hash.rb
pact_broker-2.86.0 spec/support/rspec_match_hash.rb
pact_broker-2.85.1 spec/support/rspec_match_hash.rb
pact_broker-2.85.0 spec/support/rspec_match_hash.rb
pact_broker-2.84.0 spec/support/rspec_match_hash.rb
pact_broker-2.83.0 spec/support/rspec_match_hash.rb
pact_broker-2.82.0 spec/support/rspec_match_hash.rb
pact_broker-2.81.0 spec/support/rspec_match_hash.rb
pact_broker-2.80.0 spec/support/rspec_match_hash.rb
pact_broker-2.79.1 spec/support/rspec_match_hash.rb
pact_broker-2.79.0 spec/support/rspec_match_hash.rb
pact_broker-2.78.1 spec/support/rspec_match_hash.rb
pact_broker-2.78.0 spec/support/rspec_match_hash.rb
pact_broker-2.77.0 spec/support/rspec_match_hash.rb
pact_broker-2.76.2 spec/support/rspec_match_hash.rb
pact_broker-2.76.1 spec/support/rspec_match_hash.rb
pact_broker-2.76.0 spec/support/rspec_match_hash.rb