Skip to content

Commit

Permalink
feat: Set expected interactions on mock service but without writing t…
Browse files Browse the repository at this point in the history
…hem to pact file (#210)
  • Loading branch information
thatguysimon authored Apr 25, 2020
1 parent 0a9ec9d commit 14f5327
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/pact/consumer/consumer_contract_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def initialize(attributes)
@mock_service_base_url = "http://#{attributes[:host]}:#{attributes[:port]}"
end

def without_writing_to_pact
interaction_builder.without_writing_to_pact
end

def given(provider_state)
interaction_builder.given(provider_state)
end
Expand Down
6 changes: 6 additions & 0 deletions lib/pact/consumer/interaction_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ def initialize &block
@callback = block
end

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

def upon_receiving description
@interaction.description = description
self
Expand Down
15 changes: 15 additions & 0 deletions spec/lib/pact/consumer/interaction_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ module Consumer
subject.will_respond_with response
end
end

describe "without_writing_to_pact" do
it "sets the write_to_pact key to false on metadata" do
mock_metadata = {}
expect(interaction).to receive(:metadata).and_return(nil, mock_metadata)

subject.without_writing_to_pact

expect(mock_metadata).to eq({ write_to_pact: false })
end

it "returns itself" do
expect(subject.without_writing_to_pact).to be(subject)
end
end
end
end
end

0 comments on commit 14f5327

Please sign in to comment.