Class: Pact::Interaction

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActiveSupportSupport

#fix_all_the_things, #fix_json_formatting, #fix_regexp, #remove_unicode, #warn_about_regexp

Constructor Details

#initialize(attributes = {}) ⇒ Interaction

Returns a new instance of Interaction.



10
11
12
13
14
15
16
17
18
19
# 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

Instance Attribute Details

#_idObject

Returns the value of attribute _id.



8
9
10
# File 'lib/pact/consumer_contract/interaction.rb', line 8

def _id
  @_id
end

#descriptionObject

Returns the value of attribute description.



8
9
10
# File 'lib/pact/consumer_contract/interaction.rb', line 8

def description
  @description
end

#indexObject

Returns the value of attribute index.



8
9
10
# File 'lib/pact/consumer_contract/interaction.rb', line 8

def index
  @index
end

#metadataObject

Returns the value of attribute metadata.



8
9
10
# File 'lib/pact/consumer_contract/interaction.rb', line 8

def 
  @metadata
end

#provider_stateObject

Returns the value of attribute provider_state.



8
9
10
# File 'lib/pact/consumer_contract/interaction.rb', line 8

def provider_state
  @provider_state
end

#provider_statesObject

Returns the value of attribute provider_states.



8
9
10
# File 'lib/pact/consumer_contract/interaction.rb', line 8

def provider_states
  @provider_states
end

#requestObject

Returns the value of attribute request.



8
9
10
# File 'lib/pact/consumer_contract/interaction.rb', line 8

def request
  @request
end

#responseObject

Returns the value of attribute response.



8
9
10
# File 'lib/pact/consumer_contract/interaction.rb', line 8

def response
  @response
end

Class Method Details

.from_hash(hash, options = {}) ⇒ Object



21
22
23
# File 'lib/pact/consumer_contract/interaction.rb', line 21

def self.from_hash hash, options = {}
  InteractionParser.call(hash, options)
end

Instance Method Details

#==(other) ⇒ Object



61
62
63
# 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_quotedObject



69
70
71
# 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) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/pact/consumer_contract/interaction.rb', line 65

def eq? other
  self == other
end

#http?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/pact/consumer_contract/interaction.rb', line 40

def http?
  true
end

#match_criterion(target, criterion) ⇒ Object



57
58
59
# 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) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
# 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?Boolean

Returns:

  • (Boolean)


73
74
75
# 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_hashObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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] = 
  h
end

#to_sObject



77
78
79
# File 'lib/pact/consumer_contract/interaction.rb', line 77

def to_s
  to_hash.to_s
end

#validate!Object



44
45
46
# File 'lib/pact/consumer_contract/interaction.rb', line 44

def validate!
  raise Pact::InvalidInteractionError.new(self) unless description && request && response
end