Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set expected interactions on mock service without writing them to pact file #210

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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