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

Constructor Details

#initialize(attributes) ⇒ ConsumerContractBuilder

Returns a new instance of ConsumerContractBuilder.



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

def initialize(attributes)
  @interaction_builder = nil
  @consumer_contract_details = {
    consumer: {name: attributes[:consumer_name]},
    provider: {name: attributes[:provider_name]},
    pactfile_write_mode: attributes[:pactfile_write_mode].to_s,
    pact_dir: attributes.fetch(:pact_dir)
  }
  @mock_service_client = Pact::MockService::Client.new(attributes[:port], attributes[:host])
  @mock_service_base_url = "http://#{attributes[:host]}:#{attributes[:port]}"
end

Instance Attribute Details

#mock_service_base_urlObject (readonly)

Returns the value of attribute mock_service_base_url.



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

def mock_service_base_url
  @mock_service_base_url
end

Instance Method Details

#given(provider_state) ⇒ Object



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

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

#handle_interaction_fully_defined(interaction) ⇒ Object

Raises:

  • Pact::InvalidInteractionError



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

def handle_interaction_fully_defined interaction
  interaction.validate!
  mock_service_client.add_expected_interaction interaction #TODO: What will happen if duplicate added?
  self.interaction_builder = nil
end

#log(msg) ⇒ Object



44
45
46
# File 'lib/pact/consumer/consumer_contract_builder.rb', line 44

def log msg
  mock_service_client.log msg
end

#upon_receiving(description) ⇒ Object



36
37
38
# File 'lib/pact/consumer/consumer_contract_builder.rb', line 36

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

#verify(example_description) ⇒ Object



40
41
42
# File 'lib/pact/consumer/consumer_contract_builder.rb', line 40

def verify example_description
  mock_service_client.verify example_description
end

#wait_for_interactions(options = {}) ⇒ Object



52
53
54
55
56
# File 'lib/pact/consumer/consumer_contract_builder.rb', line 52

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

#without_writing_to_pactObject



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

def without_writing_to_pact
  interaction_builder.without_writing_to_pact
end

#write_pactObject



48
49
50
# File 'lib/pact/consumer/consumer_contract_builder.rb', line 48

def write_pact
  mock_service_client.write_pact @consumer_contract_details
end