In the real world, when two parties collaborate, there often needs to be a shared understanding - a 'contract'. So is the case when two components of a system collaborate.
In this talk, I will share about contract tests, when they become useful, and some tools to help.
5. REAL LIFE: CONTRACTS
Provider
Ice cream supplier
Consumer
Supermarket
Contract
must order 1 week in advance
must pay at time of order
must deliver within 3 business days
product must not expire within 2 months
35. PLAYS WELL WITHTDD
• write consumer-driven contract test for consumer C
• red-green-refactor: consumer side
36. PLAYS WELL WITHTDD
• write consumer-driven contract test for consumer C
• red-green-refactor: consumer side
• red-green-refactor: provider side
37. PLAYS WELL WITHTDD
• write consumer-driven contract test for consumer C
• red-green-refactor: consumer side
• red-green-refactor: provider side
• make sure consumer-driven contract tests for consumers A and
B still passes too
73. person_service.
given("a person with too many friends").
upon_receiving("request for person details").
provider states
given("a person with too many friends").
74. person_service.
given("a person with too many friends").
upon_receiving("request for person details").
provider states
provider_state "a person with too many friends" do
set_up do
10_000.times do
person = Person.first
person.friends << Person.new(...)
end
end
end
75. will_respond_with(status: 200,
headers: {'Content-Type' => 'application/json;
charset=utf-8'},
body: {
id: 1,
name: Pact::SomethingLike.new(“Jane”),
age: 26,
address: ...
})
loose matching
with(method: :get,
path: "/person/1",
query: '').
person_service.
given("a person with too many friends").
upon_receiving("request for person details").
Pact::SomethingLike.new(“Jane”)