does not work with RSpec #20

ddidier opened this Issue Sep 25, 2012 · 6 comments

7 participants


I'm using RSpec to test my controller and I think the request object is stubbed (or whatever) and then the railtie is not applied to the right instance (it's too complicated for my limited knowledge of rails)...
That's working in dev mode

my controller :

class HomeController < ApplicationController
  def choose_language
    locale = http_accept_language.compatible_language_from(I18n.available_locales)
    redirect_to root_path(locale)

my test :

it "should redirect to home in the specified language" do
  request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr'
  get :choose_language
  response.should redirect_to('/fr')

the result :

2) HomeController GET choose_language should redirect to home in the specified language
 Failure/Error: get :choose_language
   undefined method `http_accept_language' for {}:Hash
 # ./app/controllers/home/home_controller.rb:14:in `choose_language'
 # ./app/controllers/application_controller.rb:73:in `block in wrap_in_transaction'
 # ./app/controllers/application_controller.rb:72:in `wrap_in_transaction'
 # ./spec/controllers/home/home_controller_spec.rb:31:in `block (3 levels) in <top (required)>'

I'm having this issue as well.


Same problem here!


Same here!


That's the same problem as #19.
You may use until the pull request is accepted.


Using the no-middleware-no-crash branch fixed the problem, thanks!


I second that, worked for me as well! Cheers.

@cawel cawel referenced this issue in DouweM/http_accept_language Jul 18, 2013
@DouweM DouweM Don't crash when used while middleware was not applied.
Middleware are not always applied when running specs.
@DouweM DouweM closed this Sep 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment