Class: Pact::Consumer::InteractionList

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/consumer/mock_service/interaction_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInteractionList

Returns a new instance of InteractionList.



8
9
10
# File 'lib/pact/consumer/mock_service/interaction_list.rb', line 8

def initialize
  clear
end

Instance Attribute Details

#interactionsObject (readonly)

Returns the value of attribute interactions.



5
6
7
# File 'lib/pact/consumer/mock_service/interaction_list.rb', line 5

def interactions
  @interactions
end

#unexpected_requestsObject (readonly)

Returns the value of attribute unexpected_requests.



6
7
8
# File 'lib/pact/consumer/mock_service/interaction_list.rb', line 6

def unexpected_requests
  @unexpected_requests
end

Instance Method Details

#add(interactions) ⇒ Object



19
20
21
# File 'lib/pact/consumer/mock_service/interaction_list.rb', line 19

def add interactions
  @interactions << interactions
end

#all_matched?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/pact/consumer/mock_service/interaction_list.rb', line 31

def all_matched?
  interaction_diffs.empty?
end

#clearObject

For testing, sigh



13
14
15
16
17
# File 'lib/pact/consumer/mock_service/interaction_list.rb', line 13

def clear
  @interactions = []
  @matched_interactions = []
  @unexpected_requests = []
end

#find_candidate_interactions(actual_request) ⇒ Object



49
50
51
52
53
# File 'lib/pact/consumer/mock_service/interaction_list.rb', line 49

def find_candidate_interactions actual_request
  interactions.select do | interaction |
    interaction.request.matches_route? actual_request
  end        
end

#interaction_diffsObject



39
40
41
42
43
44
45
46
47
# File 'lib/pact/consumer/mock_service/interaction_list.rb', line 39

def interaction_diffs
  {
    :missing_interactions => missing_interactions.collect(&:as_json),
    :unexpected_requests => unexpected_requests.collect(&:as_json)
  }.inject({}) do | hash, pair |
    hash[pair.first] = pair.last if pair.last.any?
    hash
  end
end

#missing_interactionsObject



35
36
37
# File 'lib/pact/consumer/mock_service/interaction_list.rb', line 35

def missing_interactions
  @interactions - @matched_interactions
end

#register_matched(interaction) ⇒ Object



23
24
25
# File 'lib/pact/consumer/mock_service/interaction_list.rb', line 23

def register_matched interaction
  @matched_interactions << interaction
end

#register_unexpected_request(request) ⇒ Object



27
28
29
# File 'lib/pact/consumer/mock_service/interaction_list.rb', line 27

def register_unexpected_request request
  @unexpected_requests << request
end