Skip to content

Commit 14f5327

Browse files
authored
feat: Set expected interactions on mock service but without writing them to pact file (#210)
1 parent 0a9ec9d commit 14f5327

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lib/pact/consumer/consumer_contract_builder.rb

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ def initialize(attributes)
2525
@mock_service_base_url = "http://#{attributes[:host]}:#{attributes[:port]}"
2626
end
2727

28+
def without_writing_to_pact
29+
interaction_builder.without_writing_to_pact
30+
end
31+
2832
def given(provider_state)
2933
interaction_builder.given(provider_state)
3034
end

lib/pact/consumer/interaction_builder.rb

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ def initialize &block
1313
@callback = block
1414
end
1515

16+
def without_writing_to_pact
17+
interaction.metadata ||= {}
18+
interaction.metadata[:write_to_pact] = false
19+
self
20+
end
21+
1622
def upon_receiving description
1723
@interaction.description = description
1824
self

spec/lib/pact/consumer/interaction_builder_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ module Consumer
8888
subject.will_respond_with response
8989
end
9090
end
91+
92+
describe "without_writing_to_pact" do
93+
it "sets the write_to_pact key to false on metadata" do
94+
mock_metadata = {}
95+
expect(interaction).to receive(:metadata).and_return(nil, mock_metadata)
96+
97+
subject.without_writing_to_pact
98+
99+
expect(mock_metadata).to eq({ write_to_pact: false })
100+
end
101+
102+
it "returns itself" do
103+
expect(subject.without_writing_to_pact).to be(subject)
104+
end
105+
end
91106
end
92107
end
93108
end

0 commit comments

Comments
 (0)