Class: Pact::Consumer::ConsumerContractBuilder

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/pact/consumer/consumer_contract_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, #logger

Constructor Details

#initialize(attributes) ⇒ ConsumerContractBuilder

Returns a new instance of ConsumerContractBuilder.



16
17
18
19
20
21
22
23
24
25
# File 'lib/pact/consumer/consumer_contract_builder.rb', line 16

def initialize(attributes)
  @interaction_builder = nil
  @mock_service_client = MockServiceClient.new(attributes[:provider_name], attributes[:port])
  @consumer_contract = Pact::ConsumerContract.new(
    :consumer => ServiceConsumer.new(name: attributes[:consumer_name]),
    :provider => ServiceProvider.new(name: attributes[:provider_name])
    )
  @consumer_contract.interactions = interactions_for_new_consumer_contract(attributes[:pactfile_write_mode])
  @interactions_filter = filter(@consumer_contract.interactions, attributes[:pactfile_write_mode])
end

Instance Attribute Details

#consumer_contractObject (readonly)

Returns the value of attribute consumer_contract.



14
15
16
# File 'lib/pact/consumer/consumer_contract_builder.rb', line 14

def consumer_contract
  @consumer_contract
end

#interaction_builderObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/pact/consumer/consumer_contract_builder.rb', line 35

def interaction_builder
  @interaction_builder ||=
  begin
    interaction_builder = InteractionBuilder.new
    interaction_builder.on_interaction_fully_defined do | interaction |
      self.handle_interaction_fully_defined(interaction)
    end
    interaction_builder
  end
end

Instance Method Details

#given(provider_state) ⇒ Object



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

def given(provider_state)
  interaction_builder.given(provider_state)
end

#handle_interaction_fully_defined(interaction) ⇒ Object



60
61
62
63
64
65
# File 'lib/pact/consumer/consumer_contract_builder.rb', line 60

def handle_interaction_fully_defined interaction
  interactions_filter << interaction
  mock_service_client.add_expected_interaction interaction #TODO: What will happen if duplicate added?
  consumer_contract.update_pactfile
  self.interaction_builder = nil
end

#log(msg) ⇒ Object



50
51
52
# File 'lib/pact/consumer/consumer_contract_builder.rb', line 50

def log msg
  mock_service_client.log msg
end

#upon_receiving(description) ⇒ Object



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

def upon_receiving(description)
  interaction_builder.upon_receiving(description)
end

#verify(example_description) ⇒ Object



46
47
48
# File 'lib/pact/consumer/consumer_contract_builder.rb', line 46

def verify example_description
  mock_service_client.verify example_description
end

#wait_for_interactions(options) ⇒ Object



54
55
56
57
58
# File 'lib/pact/consumer/consumer_contract_builder.rb', line 54

def wait_for_interactions options
  wait_max_seconds = options.fetch(:wait_max_seconds, 3)
  poll_interval = options.fetch(:poll_interval, 0.1)
  mock_service_client.wait_for_interactions wait_max_seconds, poll_interval
end