Class: Pact::Interaction

Inherits:
Object
  • Object
show all
Includes:
ActiveSupportSupport, SymbolizeKeys
Defined in:
lib/pact/consumer_contract/interaction.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SymbolizeKeys

included, #symbolize_keys

Methods included from ActiveSupportSupport

#fix_all_the_things, #fix_json_formatting, #fix_regexp, #remove_unicode

Constructor Details

#initialize(attributes = {}) ⇒ Interaction

Returns a new instance of Interaction.



14
15
16
17
18
19
# File 'lib/pact/consumer_contract/interaction.rb', line 14

def initialize attributes = {}
  @description = attributes[:description]
  @request = attributes[:request]
  @response = attributes[:response]
  @provider_state = attributes[:provider_state] || attributes[:providerState]
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



12
13
14
# File 'lib/pact/consumer_contract/interaction.rb', line 12

def description
  @description
end

#provider_stateObject

Returns the value of attribute provider_state.



12
13
14
# File 'lib/pact/consumer_contract/interaction.rb', line 12

def provider_state
  @provider_state
end

#requestObject

Returns the value of attribute request.



12
13
14
# File 'lib/pact/consumer_contract/interaction.rb', line 12

def request
  @request
end

#responseObject

Returns the value of attribute response.



12
13
14
# File 'lib/pact/consumer_contract/interaction.rb', line 12

def response
  @response
end

Class Method Details

.from_hash(hash) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/pact/consumer_contract/interaction.rb', line 21

def self.from_hash hash
  request_hash = Pact::MatchingRules.merge(hash['request'], hash['request']['requestMatchingRules'])
  request = Pact::Request::Expected.from_hash(request_hash)
  response_hash = Pact::MatchingRules.merge(hash['response'], hash['response']['responseMatchingRules'])
  response = Pact::Response.from_hash(response_hash)
  new(symbolize_keys(hash).merge(request: request, response: response))
end

Instance Method Details

#==(other) ⇒ Object



51
52
53
# File 'lib/pact/consumer_contract/interaction.rb', line 51

def == other
  other.is_a?(Interaction) && to_hash == other.to_hash
end

#description_with_provider_state_quotedObject



59
60
61
# File 'lib/pact/consumer_contract/interaction.rb', line 59

def description_with_provider_state_quoted
  provider_state ? "\"#{description}\" given \"#{provider_state}\"" : "\"#{description}\""
end

#eq?(other) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/pact/consumer_contract/interaction.rb', line 55

def eq? other
  self == other
end

#match_criterion(target, criterion) ⇒ Object



47
48
49
# File 'lib/pact/consumer_contract/interaction.rb', line 47

def match_criterion target, criterion
  target == criterion || (criterion.is_a?(Regexp) && criterion.match(target))
end

#matches_criteria?(criteria) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
# File 'lib/pact/consumer_contract/interaction.rb', line 38

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?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/pact/consumer_contract/interaction.rb', line 63

def request_modifies_resource_without_checking_response_body?
  request.modifies_resource? && response.body_allows_any_value?
end

#to_hashObject



29
30
31
32
33
34
35
36
# File 'lib/pact/consumer_contract/interaction.rb', line 29

def to_hash
  {
    description: description,
    provider_state: provider_state,
    request: request.to_hash,
    response: response.to_hash
  }
end

#to_sObject



67
68
69
# File 'lib/pact/consumer_contract/interaction.rb', line 67

def to_s
  to_hash.to_s
end