Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6061169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:54:28+00:00 2026-05-23T08:54:28+00:00

I am building a Rails 3 app which renders different views for mobile devices

  • 0

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…

Using Cucumber/Capybara in Rails 3, how do I set a custom User-Agent string?

The Problem…

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.

I tried to test this by adding a logger to my controller action so I could look at the user_agent headers, as follows:

def show
    # …
    logger.info("Headers: #{request.user_agent}")
    # …
end

I used an iPhone header (Buyer is the resource). In my test.log I see:

For the create action…

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

For the subsequent show action (note ‘Headers:’ is blank)…

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)

As one would expect, the ‘show me the page’ step then renders the browser page, not the mobile page I want.

How can I preserve the header so all my mobile steps run in my mobile test suite?

Update

Jnicklas (creator of the truly awesome Capybara gem!) responds:

“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.”

https://github.com/jnicklas

https://github.com/jnicklas/capybara

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:54:29+00:00Added an answer on May 23, 2026 at 8:54 am

    This feature was added to Capybara on April 25th, 2011 with this commit – https://github.com/jnicklas/capybara/commit/a00435d63085ac2e74a0f64e7b7dedc0f7252ea9

    You can can now specify a custom header when using a custom Capybara driver. See http://automagical.posterous.com/creating-a-custom-capybara-driver for code examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building my first Ruby on Rails app which is going to be
I'm building a rails 3 app in which it sells a limited number of
I am building a rails app using the wonderful activemerchant gem to save credit
I'm building an app in Ruby on Rails, and I'm including 3 of my
I'm looking at building a Rails application which will have some pretty large tables
I am building a Railo app which deals with a lot of JSON data
I'm new to rails and building a small test app on rails3 (beta4). I
Right now I'm building a project management app in rails, here is some background
I'm building an app which is going to have to handle and store a
I'm building a Rails app that needs to connect to a custom TCP data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.