pact-foundation / pact-ruby

Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://pact.io
MIT License
2.17k stars 215 forks source link

Chat about Ember/Rails #83

Closed samselikoff closed 9 years ago

samselikoff commented 9 years ago

Hi, I didn't know the best way to reach you so I figured I'd open an issue.

I'm the author of an HTTP mocking library for Ember.js called Mirage. Mirage aims to make it as simple as possible to mock out your backend so you can develop your entire frontend against a mock server.

As I've used this technique more and more, I've been thinking about ways to verify that the mock server's contract is actually fulfilled by the real server, so the tests aren't returning false positives. Someone pointed me to Pact, and after reading Ian Robinson's article & some of the Pact documentation, the concept of consumer-driven contracts seems like a really good solution to many of the problems I've been facing.

I'd love to chat about a few things to see if I can work out using Mirage to generate a contract that fulfills the Pact spec. Also, many in the Ember community use Rails as a backend, but I'm having a hard time finding much info on how to use Pact with Rails. It seems the contract verification tests you end up writing on the provider side with Pact look extremely similar to typical Rails request specs. I wonder if there's an opportunity for a library to consolidate these things.

I'm also curious about Pact's consumer library that generates a client server. The reason I made Mirage is because writing out the mocks by hand like these in each test seemed cumbersome and unmaintainable. (Many in the Ember.js community use Pretender.js for this). I would be very interested to see what the Pact mock server test definitions look like for a full application.

Anyway, I'm still getting my feet wet and would love to chat about this, perhaps on a Hangout, or here or email. My email is sam.selikoff[at]gmail.com. Thanks for all your amazing work + documentation on this lib, I've learned so much already!

uglyog commented 9 years ago

You can chat via Google groups https://groups.google.com/forum/#!forum/pact-support or, even better, via Gitter (click on the Join Gitter badge on the main page).

As to Rails support, Rails extends the Rack middleware, and Pact supports testing via Rack Test, which will work with all Rack implementations (Sinatra, Rails, etc.).

There is also a JS version of Pact for Consumer tests (https://github.com/DiUS/pact-consumer-js-dsl)

bethesque commented 9 years ago

Hi Sam,

Am very interested to talk, I've occasionally thought about providing an HTTP stubbing option as well as the service, but there are always been too many other things that were a higher priority.

In answer to your question about verifying a pact with Rails, as Ron said, it uses Rack Test. You can configure the app in the Pact.service_provider block.

Pact.service_provider "My Service Provider" do
  app { MyRailsApp }
  honours_pact_with ...
end

The pact:verify task should work as normal.

Given that you have questions that potentially relate to pact development, maybe you could post these questions to the pact-dev google group for discussion https://groups.google.com/forum/#!forum/pact-dev and we can talk about them there.

Cheers, Beth

samselikoff commented 9 years ago

Thanks for the info @bethesque! I'll post there.