From f91fc91d9890a90e2136d1ed9d0c690e073466ce Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Fri, 21 Sep 2018 15:47:20 +1000 Subject: [PATCH] chore: create pact fixture --- spec/spec_helper.rb | 5 +++++ spec/support/fixture_pact.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 spec/support/fixture_pact.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ed2b8ca1e..cb3205b53 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -33,7 +33,12 @@ PactBroker::Badges::Service.clear_cache end + config.after :suite do + Pact::Fixture.check_fixtures + end + config.include Rack::Test::Methods + config.include Pact::Fixture config.mock_with :rspec do |mocks| mocks.verify_partial_doubles = true diff --git a/spec/support/fixture_pact.rb b/spec/support/fixture_pact.rb new file mode 100644 index 000000000..9a9129044 --- /dev/null +++ b/spec/support/fixture_pact.rb @@ -0,0 +1,34 @@ +module Pact + module Fixture + + def self.fixtures + @@fixtures ||= [] + end + + def self.clear_fixtures + @@fixtures = [] + end + + def register_fixture name + source = caller.first + thing = yield + Fixture.fixtures << OpenStruct.new(name: name, thing: thing, source: source) + thing + end + + def self.check_fixtures + fixtures.group_by(&:name).each do | name, fixture_group | + if fixture_group.size == 1 + puts "WARN: Nothing to compare #{name} to." + else + if fixture_group.collect(&:thing).uniq.length != 1 + desc = fixture_group.collect do | fixture | + "#{fixture.thing} from #{fixture.source}\n" + end.join("\n") + raise "These fixtures don't match #{fixture_group.first.name}:\n #{desc}" + end + end + end + end + end +end