lib/pacto/contract.rb in pacto-0.2.5 vs lib/pacto/contract.rb in pacto-0.3.0.pre
- old
+ new
@@ -1,22 +1,36 @@
module Pacto
class Contract
- def initialize(request, response)
+ attr_reader :values
+ attr_reader :request, :response
+
+ def initialize(request, response, file = nil)
@request = request
@response = response
+ @file = file
end
- def instantiate(values = nil)
- instantiated_contract = InstantiatedContract.new(@request, @response.instantiate)
- instantiated_contract.replace!(values) unless values.nil?
- instantiated_contract
+ def stub_contract! values = {}
+ @values = values
+ @stub = Pacto.configuration.provider.stub_request!(@request, stub_response) unless @request.nil?
end
- def validate
- response_gotten = @request.execute
- if ENV["DEBUG_CONTRACTS"]
- puts "[DEBUG] Response: #{response_gotten.inspect}"
- end
- @response.validate(response_gotten)
+ def validate(response_gotten = provider_response, opt = {})
+ @response.validate(response_gotten, opt)
end
+
+ def matches? request_signature
+ @stub.matches? request_signature unless @stub.nil?
+ end
+
+ private
+
+ def provider_response
+ @request.execute
+ end
+
+ def stub_response
+ @response.instantiate
+ end
+
end
end