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.

This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.
  • http://www.google.com/profiles/myron.marston Myron

    Hmm…I think the issue here is that the post hits rack-test directly, whereas the visit goes through capybara. I haven't had any problems with capybara's cookie handling, but all of my usage has used the capyabara API.

    FWIW, there was an extensive discussion on the google group before adding the ability to do a direct GET/POST/PUT/DELETE:

    http://groups.google.com/group/ruby-capybara/br

    • http://www.facebook.com/davidkrmpotic Давид Крмпотарович

      that works!

      page.driver.post …

      and session is shared!

  • http://www.google.com/profiles/myron.marston Myron

    Hmm…I think the issue here is that the post hits rack-test directly, whereas the visit goes through capybara. I haven't had any problems with capybara's cookie handling, but all of my usage has used the capyabara API.

    FWIW, there was an extensive discussion on the google group before adding the ability to do a direct GET/POST/PUT/DELETE:

    http://groups.google.com/group/ruby-capybara/br

  • http://benlakey.com/ Ben Lakey

    I ran into this as well. When requesting a page via capybara with ‘visit’, rack-test’s ‘last_response’ wasn’t set at all. I kept getting “Rack::Test::Error: No response yet. Request a page first.”