Setting HTTP Referer with capybara
Because it took me an hour to find out… To set the HTTP Referer for a request in a cucumber step definition using capybara with the default driver (Capybara::RackTest::Driver):
referer = 'http://example.com/' Capybara.current_session.driver.header 'Referer', referer visit '/'
Note that this persists for the remainder of the session. If you know how you’re supposed to unset an header, please be nice and leave a comment.
