lib/pact/mock_service/client.rb in pact-mock_service-2.9.8 vs lib/pact/mock_service/client.rb in pact-mock_service-2.10.0

- old
+ new

@@ -1,21 +1,27 @@ require 'net/http' require 'pact/mock_service/interaction_decorator' +require 'pact/errors' module Pact module MockService + + class VerificationFailedError < Pact::Error; end + class AddInteractionError < Pact::Error; end + class WritePactError < Pact::Error; end + class Client MOCK_SERVICE_ADMINISTRATON_HEADERS = {'X-Pact-Mock-Service' => 'true'} def initialize port @http = Net::HTTP.new('localhost', port) end def verify example_description response = http.request_get("/interactions/verification?example_description=#{CGI.escape(example_description)}", MOCK_SERVICE_ADMINISTRATON_HEADERS) - raise "\e[31m#{response.body}\e[m" unless response.is_a? Net::HTTPSuccess + raise VerificationFailedError.new("\e[31m#{response.body}\e[m") unless response.is_a? Net::HTTPSuccess end def log msg http.request_get("/log?msg=#{CGI.escape(msg)}", MOCK_SERVICE_ADMINISTRATON_HEADERS) end @@ -35,20 +41,20 @@ response = http.request_post( '/interactions', interaction_json(interaction), MOCK_SERVICE_ADMINISTRATON_HEADERS.merge("Content-Type" => "application/json") ) - raise "\e[31m#{response.body}\e[m" unless response.is_a? Net::HTTPSuccess + raise AddInteractionError.new("\e[31m#{response.body}\e[m") unless response.is_a? Net::HTTPSuccess end def self.clear_interactions port, example_description Net::HTTP.new("localhost", port).delete("/interactions?example_description=#{CGI.escape(example_description)}", MOCK_SERVICE_ADMINISTRATON_HEADERS) end def write_pact pacticipant_details response = http.request_post("/pact", pacticipant_details.to_json, MOCK_SERVICE_ADMINISTRATON_HEADERS.merge("Content-Type" => "application/json")) - raise "\e[31m#{response.body}\e[m" unless response.is_a? Net::HTTPSuccess + raise WritePactError.new("\e[31m#{response.body}\e[m") unless response.is_a? Net::HTTPSuccess response.body end private @@ -65,9 +71,8 @@ end def interaction_json interaction Pact::MockService::InteractionDecorator.new(interaction).to_json end - end end -end \ No newline at end of file +end