does not work with RSpec #20

Closed
ddidier opened this Issue Sep 25, 2012 · 6 comments

7 participants

@ddidier

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
thanks

my controller :

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

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')
end

the result :

2) HomeController GET choose_language should redirect to home in the specified language
 Failure/Error: get :choose_language
 NoMethodError:
   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)>'
@progressions

I'm having this issue as well.

@Jell

Same problem here!

@rafaelgonzalez

Same here!

@inkstak

That's the same problem as #19.
You may use https://github.com/DouweM/http_accept_language until the pull request is accepted.

@lacco

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

@rafaelgonzalez

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.
fa57cfb
@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