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 506191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:40:32+00:00 2026-05-13T06:40:32+00:00

I test my application with Cucumber and it worked before I’ve added auto-detection of

  • 0

I test my application with Cucumber and it worked before I’ve added auto-detection of locales from WWW browser in application_controller.rb:

  before_filter :set_locale

  private

    def set_locale
      xxx = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
      if xxx.match /^(en|fr)$/
        I18n.locale = xxx
      else
        I18n.locale = 'en'
      end
    end

I have a scenario:

  Scenario: Successful sign up
    Given I am an anonymous user
    And I am on the home page
    When ...

When I run cucumber, I get an error:

Given I am an anonymous user                   # features/step_definitions/user_steps.rb:7
And I am on the home page                      # features/step_definitions/webrat_steps.rb:6
  private method `scan' called for nil:NilClass (NoMethodError)
  C:/workspace/jeengle/app/controllers/application_controller.rb:33:in `set_locale'
  c:/worktools/ruby/lib/ruby/1.8/benchmark.rb:308:in `realtime'
  (eval):2:in `/^I am on (.+)$/'
  features/manage_users.feature:8:in `And I am on the home page'

I have tried to do it in before statement in step_definitions folder:

Before do
  request.env['HTTP_ACCEPT_LANGUAGE'] = "en"
end

but I’ve got another error:

  undefined method `env' for nil:NilClass (NoMethodError)

Does anybody know how to initialize/emulate request.env[‘HTTP_ACCEPT_LANGUAGE’] in Cucumber?


UPDATED

Cucumber test passed when I rewritted set_locale method:

  xxx = request.env['HTTP_ACCEPT_LANGUAGE']    
  if xxx
    xxx = xxx.scan(/^[a-z]{2}/).first
    if xxx.match /^(en|ru)$/
      I18n.locale = xxx
  end
  else
    I18n.locale = 'en'
  end

It’s not a solution but it works.

  • 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-13T06:40:32+00:00Added an answer on May 13, 2026 at 6:40 am

    Actually the problem lies in Webrat, not Cucumber. The sequence of events is (roughly)

    • Cucumber runs your feature
    • When the “I am on the home page” step is reached, it invokes Webrat to make the request to the controller
    • Webrat constructs a request and sends it to the controller
    • Step fails because the request does not have an “Accept-Language” header

    Apparently Webrat does not add this header when it builds the request. However, Webrat gives you a workaround: the “header” method, with which any header can be set for the duration of the request.

    So to make this work add a step that puts in the header, e.g.:

    Given /^an Accept Language header$/ do
      header "Accept-Language", "en;en-us" # or whatever value you need for testing
    end`
    

    Run this step before you visit a page and Webrat is no longer confused.

    btw I got this from The Rspec Book, which really does a good job explaining how this BDD stuff fits together.

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

Sidebar

Related Questions

I created a test application that generates 10k random numbers in a range from
I'm using cucumber to test my rails 3.1 application and i'm using devise for
Is there possibility to test application before posting it to Google Apps marketplace for
I am using Cucumber, webrat and selenium to test a web application. I use
I am trying to test my application with cucumber, capybara, capybara-webkit, spork and rspec
This is a test application: #!/usr/bin/env python from flask import Flask from time import
If, as part of an RSpec or Cucumber test in my Rails application, I
I have a test application that allows the user to select a culture from
I am building a test application using MVC3, Razor, and Entity Framework 4.1 with
I have a simple test application (C# console application) that does an HTTP GET

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.