Skip to content

Commit

Permalink
chore: create pact fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 21, 2018
1 parent 615025e commit f91fc91
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions spec/support/fixture_pact.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f91fc91

Please sign in to comment.