lib/pacto/contract.rb in pacto-0.3.0.pre vs lib/pacto/contract.rb in pacto-0.3.0

- old
+ new

@@ -1,36 +1,39 @@ module Pacto class Contract - attr_reader :values - attr_reader :request, :response + attr_reader :name, :values, :request, :response, :file, :request_pattern - def initialize(request, response, file = nil) + def initialize(request, response, file, name = nil, request_pattern_provider = RequestPattern) @request = request @response = response - @file = file + @file = file.to_s + @name = name || @file + @request_pattern = request_pattern_provider.for(request) + @values = {} end - def stub_contract! values = {} + def stub_contract!(values = {}) @values = values - @stub = Pacto.configuration.provider.stub_request!(@request, stub_response) unless @request.nil? + Pacto.configuration.provider.stub_request!(request, response) end - def validate(response_gotten = provider_response, opt = {}) - @response.validate(response_gotten, opt) + def validate_provider(opts = {}) + request = @request + response = provider_response + validate_consumer request, response, opts end - def matches? request_signature - @stub.matches? request_signature unless @stub.nil? + def validate_consumer(request, response, opts = {}) + Pacto::ContractValidator.validate self, request, response, opts end + def matches?(request_signature) + request_pattern.matches? request_signature + end + private def provider_response @request.execute end - - def stub_response - @response.instantiate - end - end end