In my Rails 3 app, I have different layouts for iPhone and desktop browsers. I am trying to verify iPhone layout using Cucumber / Capybara. So far, all attempts to set the iPhone User-Agent string in the HTTP request header have failed.
I followed Testing Custom Headers and ssl with Cucumber and Capybara , but it does not seem to set the User-Agent string in the HTTP request.
If I just view the Rails application using my iPhone, I get the correct layout. I use Rack-Mobile-Detect to install Rails request.format in: iphone.
Any ideas on how to make this work? I am ready for the ditch of Capybara and will return to Webrath.
Here is what I still have:
Feature: Detect Browser In order to have different layouts for iPhone vs. desktop browsers As a developer I want to show different layouts for different browsers Scenario: Show home page with desktop layout Given I am using "a desktop browser" When I go to "the home page" Then I should see "desktop browser" Scenario: Show home page with iPhone layout Given I am using "mobile safari" When I go to "the home page" Then show me the page Then I should see "mobile safari"
Detect_browser_steps.rb
Given /^(?:|I )am using (.+)$/ do |browser| case browser when "mobile safari" agent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16" add_headers({'User-Agent' => agent}) else
headers_hack.rb
# http://aflatter.de/2010/06/testing-headers-and-ssl-with-cucumber-and-capybara/
Doug Aug 03 '10 at 17:44 2010-08-03 17:44
source share