Sha256: b5f8c84809593a60b824f47d27c4d436f9f5e04c2f9f9a0f7ed027b7c6d90045
Contents?: true
Size: 1.85 KB
Versions: 7
Compression:
Stored size: 1.85 KB
Contents
require 'pact/consumer_contract/request' require 'pact/consumer_contract/response' require 'pact/symbolize_keys' require 'pact/shared/active_support_support' module Pact class Interaction include ActiveSupportSupport include SymbolizeKeys attr_accessor :description, :request, :response, :provider_state def initialize attributes = {} @description = attributes[:description] @request = attributes[:request] @response = attributes[:response] @provider_state = attributes[:provider_state] || attributes[:providerState] end def self.from_hash hash request = Pact::Request::Expected.from_hash(hash['request']) response = Pact::Response.from_hash(hash['response']) new(symbolize_keys(hash).merge({request: request, response: response})) end def to_hash { description: description, provider_state: provider_state, request: request.to_hash, response: response.to_hash } end def matches_criteria? criteria criteria.each do | key, value | unless match_criterion self.send(key.to_s), value return false end end true end def match_criterion target, criterion target == criterion || (criterion.is_a?(Regexp) && criterion.match(target)) end def == other other.is_a?(Interaction) && to_hash == other.to_hash end def eq? other self == other end def description_with_provider_state_quoted provider_state ? "\"#{description}\" given \"#{provider_state}\"" : "\"#{description}\"" end def request_modifies_resource_without_checking_response_body? request.modifies_resource? && response.body_allows_any_value? end def to_s to_hash.to_s end end end
Version data entries
7 entries across 7 versions & 1 rubygems