Class: Pact::Message::Consumer::ConsumerContractBuilder

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

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ ConsumerContractBuilder

Returns a new instance of ConsumerContractBuilder.



10
11
12
13
14
15
16
17
18
# File 'lib/pact/message/consumer/consumer_contract_builder.rb', line 10

def initialize(attributes)
  @interaction_builder = nil
  @consumer_name = attributes[:consumer_name]
  @provider_name = attributes[:provider_name]
  @pact_specification_version = attributes[:pact_specification_version]
  @pact_dir = attributes[:pact_dir]
  @interactions = []
  @yielded_interaction = false
end

Instance Method Details

#given(provider_state, params = {}) ⇒ Object



25
26
27
# File 'lib/pact/message/consumer/consumer_contract_builder.rb', line 25

def given(provider_state, params = {})
  interaction_builder.given(provider_state, params)
end

#handle_interaction_fully_defined(interaction) ⇒ Object



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

def handle_interaction_fully_defined(interaction)
  @contents = interaction.contents
  @contents_string = interaction.contents.to_s
end

#is_expected_to_send(description) ⇒ Object



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

def is_expected_to_send(description)
  interaction_builder.is_expected_to_send(provider_state)
end

#resetObject



20
21
22
23
# File 'lib/pact/message/consumer/consumer_contract_builder.rb', line 20

def reset
  @interaction_builder = nil
  @yielded_interaction = false
end

#send_message_hashObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/pact/message/consumer/consumer_contract_builder.rb', line 44

def send_message_hash
  if interaction_builder?
    if block_given?
      @yielded_interaction = true
      yield interaction_builder.interaction.contents.reified_contents_hash
    end
  else
    raise Pact::Error.new("No message expectation has been defined")
  end
end

#send_message_stringObject



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

def send_message_string
  if interaction_builder?
    if block_given?
      @yielded_interaction = true
      yield interaction_builder.interaction.contents.reified_contents_string
    end
  else
    raise Pact::Error.new("No message expectation has been defined")
  end
end

#verify(example_description) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pact/message/consumer/consumer_contract_builder.rb', line 60

def verify example_description
  # There may be multiple message providers defined, and not every one of them
  # has to define a message for every test.
  if interaction_builder?
    if yielded_interaction?
      interactions << interaction_builder.interaction
    else
      raise Pact::Error.new("`send_message_string` was not called for message \"#{interaction_builder.interaction.description}\"")
    end
  end
end

#write_pactObject



72
73
74
# File 'lib/pact/message/consumer/consumer_contract_builder.rb', line 72

def write_pact
  Pact::Message::Consumer::WritePact.call(interactions, pact_dir, consumer_name, provider_name, pact_specification_version, :overwrite)
end