-
Notifications
You must be signed in to change notification settings - Fork 216
Yes. We're working on this with the v4 generators.
By default, a mock service will be started automatically by the pact gem when running the consumer tests. A standalone mock service can be run locally and is useful for debugging purposes.
Pact.service_consumer "My Service Consumer" do
has_pact_with "My Service Provider" do
mock_service :my_service_provider do
port <port-num>
standalone true #Tell the pact gem not to automatically start the mock service
end
end
end
$ bundle exec pact-mock-service -p <port-num>
The service prints messages it recieves to stdout which can be really useful when diagnosing issues with pacts.
Use the set_up and tear_down hooks in the provider state definition:
Pact.provider_states_for "Some Consumer" do
set_up do
# Set up code here
end
tear_down do
# tear down code here
end
end
See https://www.relishapp.com/rspec/rspec-core/docs/hooks/filters for more information.
Eg. for Capybara tests
Pact.service_consumer "My Consumer" do
app <your rack app here>
port 4321
end
RFC 2616 states that two headers with the same name can interpreted as a single header with two comma-separated values. This is the safest way to specify multiple headers with the same name, as Rack will only pass the last value through when they are defined separately (see https://github.com/rack/rack/issues/436).
my_service_provider.
.given("it is RFC 2616 compliant")
.upon_receiving("a request with a header with commas separated values")
.with( method: :get, path: '/', headers: {'X-Request-Multival' => "A, B"} )
.will_respond_with(
status: 200, headers: {'X-Response-Multival' => "C, D"}
)