class Pact::Consumer::ConsumerContractBuilder

Attributes

interaction_builder[W]
mock_service_base_url[R]
mock_service_client[R]

Public Class Methods

new(attributes) click to toggle source
# 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

Public Instance Methods

given(provider_state) click to toggle source
# 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) click to toggle source

@raise Pact::InvalidInteractionError

# 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) click to toggle source
# File lib/pact/consumer/consumer_contract_builder.rb, line 44
def log msg
  mock_service_client.log msg
end
upon_receiving(description) click to toggle source
# File lib/pact/consumer/consumer_contract_builder.rb, line 36
def upon_receiving(description)
  interaction_builder.upon_receiving(description)
end
verify(example_description) click to toggle source
# 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 = {}) click to toggle source
# 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_pact() click to toggle source
# File lib/pact/consumer/consumer_contract_builder.rb, line 28
def without_writing_to_pact
  interaction_builder.without_writing_to_pact
end
write_pact() click to toggle source
# File lib/pact/consumer/consumer_contract_builder.rb, line 48
def write_pact
  mock_service_client.write_pact @consumer_contract_details
end

Private Instance Methods

interaction_builder() click to toggle source
# File lib/pact/consumer/consumer_contract_builder.rb, line 70
def interaction_builder
  @interaction_builder ||=
  begin
    interaction_builder = InteractionBuilder.new do | interaction |
      handle_interaction_fully_defined(interaction)
    end
    interaction_builder
  end
end