title: Capybara does not pass header after form submit
body: <p>I am building a Rails 3 app which renders different views for mobile devices (using jQuery Mobile) and regular desktop browsers. I am testing with Cucumber/Capybara, and have separate test suites for mobile and browser. I am able to set a mobile User-Agent string in the request's HTTP header just fine using the ‘headers hack’ found here…</p>
  
  <p><a href="https://stackoverflow.com/questions/3399156/using-cucumber-capybara-in-rails-3-how-do-i-set-a-custom-user-agent-string">Using Cucumber/Capybara in Rails 3, how do I set a custom User-Agent string?</a></p>
  
  <p>The Problem...</p>
  
  <p>Most of my mobile Cucumber steps work fine (e.g., I set the mobile header in a step, thereafter the mobile views render). However after a form submit, the test then renders a browser view of the next step (not the mobile view I want). I think this may be because Capybara is dropping the header after a form submit action.</p>
  
  <p>I tried to test this by adding a logger to my controller action so I could look at the user_agent headers, as follows:</p>
  
  <pre><code>def show
      # …
      logger.info("Headers: #{request.user_agent}")
      # …
  end
  </code></pre>
  
  <p>I used an iPhone header (Buyer is the resource). In my test.log I see:</p>
  
  <p>For the create action…</p>
  
  <pre><code>Started POST "/buyers" for 127.0.0.1 at 2011-04-19 16:49:18 -0700
  Processing by BuyersController#create as HTML
    #...
  Headers: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
    #...
  Redirected to http://www.example.com/buyers/1
  Completed 302 Found in 7ms
  </code></pre>
  
  <p>For the subsequent show action (note ‘Headers:’ is blank)…</p>
  
  <pre><code>Started GET "/buyers/1" for 127.0.0.1 at 2011-04-19 16:49:18 -0700
  Processing by BuyersController#show as HTML
   #...
  Headers: 
   #...
  Completed 200 OK in 4ms (Views: 2.8ms | ActiveRecord: 1.4ms)
  </code></pre>
  
  <p>As one would expect, the ‘show me the page’ step then renders the browser page, not the mobile page I want.</p>
  
  <p>How can I preserve the header so all my mobile steps run in my mobile test suite?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Jnicklas (creator of the truly awesome Capybara gem!) responds:</p>
  
  <p>“This is more of a question than an issue, tbh. In Rack-Test there is currently there no way of achieving this short of monkey patching that I am aware of. I've been thinking about adding a header option to the rack-test driver, which would allow the passing in of different header options. If you're using a lot of JavaScript, Selenium might be a better fit anyway and allows you to set the user agent freely, IIRC.”</p>
  
  <p><a href="https://github.com/jnicklas" rel="nofollow noreferrer">https://github.com/jnicklas</a></p>
  
  <p><a href="https://github.com/jnicklas/capybara" rel="nofollow noreferrer">https://github.com/jnicklas/capybara</a></p>