lib/pact/consumer/mock_service/app.rb in pact-mock_service-0.2.2 vs lib/pact/consumer/mock_service/app.rb in pact-mock_service-0.2.3.pre.rc1
- old
+ new
@@ -1,13 +1,14 @@
require 'rack'
require 'uri'
require 'json'
require 'logger'
require 'awesome_print'
-require 'awesome_print/core_ext/logger' #For some reason we get an error indicating that the method 'ap' is private unless we load this specifically
require 'pact/consumer/request'
-require 'pact/consumer/mock_service/interaction_list'
+require 'pact/consumer/mock_service/expected_interactions'
+require 'pact/consumer/mock_service/actual_interactions'
+require 'pact/consumer/mock_service/verified_interactions'
require 'pact/consumer/mock_service/interaction_delete'
require 'pact/consumer/mock_service/interaction_post'
require 'pact/consumer/mock_service/interaction_replay'
require 'pact/consumer/mock_service/missing_interactions_get'
require 'pact/consumer/mock_service/verification_get'
@@ -26,29 +27,33 @@
class MockService
def initialize options = {}
log_description = configure_logger options
- interaction_list = InteractionList.new
@name = options.fetch(:name, "MockService")
- interactions = []
+ pact_dir = options[:pact_dir]
+ expected_interactions = ExpectedInteractions.new
+ actual_interactions = ActualInteractions.new
+ verified_interactions = VerifiedInteractions.new
+
@handlers = [
- MissingInteractionsGet.new(@name, @logger, interaction_list),
- VerificationGet.new(@name, @logger, interaction_list, log_description),
- InteractionPost.new(@name, @logger, interaction_list),
- InteractionDelete.new(@name, @logger, interaction_list),
+ MissingInteractionsGet.new(@name, @logger, expected_interactions, actual_interactions),
+ VerificationGet.new(@name, @logger, expected_interactions, actual_interactions, log_description),
+ InteractionPost.new(@name, @logger, expected_interactions, verified_interactions),
+ InteractionDelete.new(@name, @logger, expected_interactions, actual_interactions),
LogGet.new(@name, @logger),
- PactPost.new(@name, @logger, interactions),
- InteractionReplay.new(@name, @logger, interaction_list, interactions)
+ PactPost.new(@name, @logger, verified_interactions, pact_dir),
+ InteractionReplay.new(@name, @logger, expected_interactions, actual_interactions, verified_interactions)
]
end
def configure_logger options
options = {log_file: $stdout}.merge options
log_stream = options[:log_file]
@logger = Logger.new log_stream
+ @logger.formatter = options[:log_formatter] if options[:log_formatter]
@logger.level = Pact.configuration.logger.level
if log_stream.is_a? File
File.absolute_path(log_stream).gsub(Dir.pwd + "/", '')
else
@@ -62,23 +67,21 @@
def call env
response = []
begin
relevant_handler = @handlers.detect { |handler| handler.match? env }
- response = relevant_handler.respond env
+ response = relevant_handler.respond(env)
rescue StandardError => e
- @logger.error 'Error ocurred in mock service:'
- @logger.ap e, :error
- @logger.ap e.backtrace
+ @logger.error "Error ocurred in mock service: #{e.class} - #{e.message}"
+ @logger.error e.backtrace.join("\n")
response = [500, {'Content-Type' => 'application/json'}, [{message: e.message, backtrace: e.backtrace}.to_json]]
rescue Exception => e
- @logger.error 'Exception ocurred in mock service:'
- @logger.ap e, :error
- @logger.ap e.backtrace
+ @logger.error "Exception ocurred in mock service: #{e.class} - #{e.message}"
+ @logger.error e.backtrace.join("\n")
raise e
end
response
end
end
end
-end
\ No newline at end of file
+end