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

前端 未结 2 1371
长发绾君心
长发绾君心 2020-12-20 02:28

In my Rails 3 app, I have different layouts for iPhone vs desktop browsers. I\'m trying to test the iPhone layout using Cucumber/Capybara. So far, all my attempts at setting

相关标签:
2条回答
  • 2020-12-20 03:20

    Had to fiddle a bit on this, but in the end I managed to get it working just by adding:

    # features/support/capybara_headers.rb:
    
    module CapybaraHeadersHelper
      def add_headers(headers)
        headers.each do |name, value|
          page.driver.browser.header(name, value)
        end
      end
    end
    World(CapybaraHeadersHelper)
    

    You can get more info in this blog post I wrote, but that's basically it.

    0 讨论(0)
  • 2020-12-20 03:27

    Hey there. Glad you found my post ;-)

    Did you check if Rack::Test passes your header to the controller? You could try something like Rails.logger.info("Headers: #{headers.inspect}")in your controller and then inspect your log file.

    0 讨论(0)
提交回复
热议问题