Rack-Test and Capybara are uneasy bedfellows

I’m using Capybara on a new project because apparently it’s the new hotness. Today I found out that all is not peaceful in the Cucumber/Capybara/Rack-Test stack. There is a cold war going on, and both Capy and Rack-test are jealously guarding their own cookie jars.

Why does this matter? Well, say you use post '/some_callback', :some => "data" in your tests to simulate a callback from an external service like Janrain. Then you use visit '/' to simulate the user loading a page after the callback.

Any cookies set during the post will be ignored by the visit call, because like I said earlier, Capy and Rack-Test don’t share cookies. So if that callback action set up a user session, that session is now lost from the point of view of Capybara (and all the Cucumber steps that use Capybara).

Putting this out there in case anyone else runs into it and is as befuddled as I was.