class Pact::Interaction

Attributes

_id[RW]
description[RW]
index[RW]
metadata[RW]
provider_state[RW]
provider_states[RW]
request[RW]
response[RW]

Public Class Methods

from_hash(hash, options = {}) click to toggle source
# File lib/pact/consumer_contract/interaction.rb, line 21
def self.from_hash hash, options = {}
  InteractionParser.call(hash, options)
end
new(attributes = {}) click to toggle source
# File lib/pact/consumer_contract/interaction.rb, line 10
def initialize attributes = {}
  @description = attributes[:description]
  @request = attributes[:request]
  @response = attributes[:response]
  @provider_state = attributes[:provider_state] || attributes[:providerState]
  @provider_states = attributes[:provider_states]
  @metadata = attributes[:metadata]
  @_id = attributes[:_id]
  @index = attributes[:index]
end

Public Instance Methods

==(other) click to toggle source
# File lib/pact/consumer_contract/interaction.rb, line 61
def == other
  other.is_a?(Interaction) && to_hash == other.to_hash
end
description_with_provider_state_quoted() click to toggle source
# File lib/pact/consumer_contract/interaction.rb, line 69
def description_with_provider_state_quoted
  provider_state ? "\"#{description}\" given \"#{provider_state}\"" : "\"#{description}\""
end
eq?(other) click to toggle source
# File lib/pact/consumer_contract/interaction.rb, line 65
def eq? other
  self == other
end
http?() click to toggle source
# File lib/pact/consumer_contract/interaction.rb, line 40
def http?
  true
end
match_criterion(target, criterion) click to toggle source
# File lib/pact/consumer_contract/interaction.rb, line 57
def match_criterion target, criterion
  target == criterion || (criterion.is_a?(Regexp) && criterion.match(target))
end
matches_criteria?(criteria) click to toggle source
# File lib/pact/consumer_contract/interaction.rb, line 48
def matches_criteria? criteria
  criteria.each do | key, value |
    unless match_criterion self.send(key.to_s), value
      return false
    end
  end
  true
end
request_modifies_resource_without_checking_response_body?() click to toggle source
# File lib/pact/consumer_contract/interaction.rb, line 73
def request_modifies_resource_without_checking_response_body?
  request.modifies_resource? && response.body_allows_any_value?
end
to_hash() click to toggle source
# File lib/pact/consumer_contract/interaction.rb, line 25
def to_hash
  h = { description: description }

  if provider_states
    h[:provider_states] = provider_states.collect(&:to_hash)
  else
    h[:provider_state] = provider_state
  end

  h[:request] = request.to_hash
  h[:response] = response.to_hash
  h[:metadata] = metadata
  h
end
to_s() click to toggle source
# File lib/pact/consumer_contract/interaction.rb, line 77
def to_s
  to_hash.to_s
end
validate!() click to toggle source
# File lib/pact/consumer_contract/interaction.rb, line 44
def validate!
  raise Pact::InvalidInteractionError.new(self) unless description && request && response
end