Mind Dump, Tech And Life Blog
written by Ivan Alenko

Capybara Dropping Session During Test

Capybara with Rack::Test driver drops session during test, which means you lose current_user, authentication. Rack::Test uses by default HTTP_HOST set to “http://www.example.com”. I don’t know why, but after login, HTTP_HOST was “localhost”.

The solution - fix capybara default host. Put this into rails_helper.rb or you know, support files which are loaded by it.

Capybara.default_host = 'http://localhost'

When I tried to set it to example.com - Capybara.default_host = 'http://example.com', didn’t work, still changed to localhost.