Skip to content

Commit

Permalink
test: fix ordering problem in test
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Nov 1, 2017
1 parent ff8624e commit 2c34325
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions spec/lib/pact_broker/matrix/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ def build_selectors(hash)
end

it "returns an row with a blank provider_version_number" do
expect(subject.first).to include consumer_name: "A",
expect(subject).to include_hash_matching consumer_name: "A",
provider_name: "B",
consumer_version_number: "1.2.3",
provider_version_number: nil

expect(subject.last).to include consumer_name: "A",
expect(subject).to include_hash_matching({consumer_name: "A",
provider_name: "C",
consumer_version_number: "1.2.3",
provider_version_number: nil
provider_version_number: nil})
end

context "when only 2 version selectors are specified" do
Expand Down
10 changes: 10 additions & 0 deletions spec/support/shared_examples_for_responses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@
expect(actual.status).to be 404
end
end

RSpec::Matchers.define :include_hash_matching do |expected|
match do |array_of_hashes|
array_of_hashes.any? { |actual| slice(actual, expected.keys) == expected }
end

def slice actual, keys
keys.each_with_object({}) { |k, hash| hash[k] = actual[k] if actual.has_key?(k) }
end
end

0 comments on commit 2c34325

Please sign in to comment.