Myron Marston | 10 Apr 21:14 2010

[Cucumber:4039] [Capybara/Rack-Test] Integration testing external sites/redirects

I'm working on integrating my current project with braintree, which
has an API that allows your users to submit their credit card details
directly to them, where they are redirected back to your site, so as
to avoid the security risks involved in dealing with the credit card
data directly.

It wasn't obvious how to write a cucumber scenario that does all this,
so it was with great interest that I found this old thread[1] about
this very topic (involving braintree, too!).

I came up with what I think is a pretty great solution, and was going
to reply to that thread with it, but I noticed that the "reply" option
is no longer available--apparently you can't resurrect old threads?
(Probably a good thing, I guess).

In case anyone else has this issue, I wanted to share my solution.
The underlying problem is that rack-test makes all requests to your
rack app, even when processing a form submission to an entirely
different domain.  Luckily, the modularity of rack allows you to swap
our your rack app with any other rack app, and the rack-client gem[2]
provides a rack app that simply delegates to Net::HTTP under the
covers.  So, you simply swap out your rack app with a Rack::Client
instance before making a request to an external domain.  My gist[3]
has the code I use for this.

I'm also using FakeWeb and my VCR gem to handle recording and
replaying the Net::HTTP requests so my scenarios are fast and




You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes@...
To unsubscribe from this group, send email to cukes+unsubscribe@...
For more options, visit this group at