Class: Pact::Consumer::InteractionBuilder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ InteractionBuilder

Returns a new instance of InteractionBuilder.



11
12
13
14
# File 'lib/pact/consumer/interaction_builder.rb', line 11

def initialize &block
  @interaction = Interaction.new
  @callback = block
end

Instance Attribute Details

#interactionObject (readonly)

Returns the value of attribute interaction.



9
10
11
# File 'lib/pact/consumer/interaction_builder.rb', line 9

def interaction
  @interaction
end

Instance Method Details

#given(provider_state) ⇒ Object



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

def given provider_state
  @interaction.provider_state = provider_state.nil? ? nil : provider_state.to_s
  self
end

#upon_receiving(description) ⇒ Object



22
23
24
25
# File 'lib/pact/consumer/interaction_builder.rb', line 22

def upon_receiving description
  @interaction.description = description
  self
end

#will_respond_with(response) ⇒ Object



37
38
39
40
41
# File 'lib/pact/consumer/interaction_builder.rb', line 37

def will_respond_with(response)
  interaction.response = Pact::Response.new(response)
  @callback.call interaction
  self
end

#with(request_details) ⇒ Object



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

def with(request_details)
  interaction.request = Pact::Request::Expected.from_hash(request_details)
  self
end

#without_writing_to_pactObject



16
17
18
19
20
# File 'lib/pact/consumer/interaction_builder.rb', line 16

def without_writing_to_pact
  interaction. ||= {}
  interaction.[:write_to_pact] = false
  self
end