lib/pact/mock_service/app.rb in pact-mock_service-2.3.0 vs lib/pact/mock_service/app.rb in pact-mock_service-2.4.0

- old
+ new

@@ -18,10 +18,11 @@ def initialize options = {} logger = Logger.from_options(options) @name = options.fetch(:name, "MockService") @session = Session.new(options.merge(logger: logger)) + setup_stub(options[:stub_pactfile_paths]) if options[:stub_pactfile_paths] && options[:stub_pactfile_paths].any? request_handlers = RequestHandlers.new(@name, logger, @session, options) @app = Rack::Builder.app do use Pact::Consumer::MockService::ErrorHandler, logger use Pact::Consumer::CorsOriginHeaderMiddleware, options[:cors_enabled] run request_handlers @@ -32,9 +33,18 @@ @app.call env end def shutdown write_pact_if_configured + end + + def setup_stub stub_pactfile_paths + stub_pactfile_paths.each do | pactfile_path | + $stdout.puts "Loading interactions from #{pactfile_path}" + hash_interactions = JSON.parse(File.read(pactfile_path))['interactions'] + interactions = hash_interactions.collect { | hash | Interaction.from_hash(hash) } + @session.set_expected_interactions interactions + end end def write_pact_if_configured consumer_contract_writer = ConsumerContractWriter.new(@session.consumer_contract_details, StdoutLogger.new) if consumer_contract_writer.can_write? && !@session.pact_written?