session variable not available in global before(:each, :type => :controller)

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2011-01-14T09:49:12Z Indexed on 2011/01/14 9:53 UTC
Read the original article Hit count: 146

Filed under:
|
|

Hi, I'm refactoring some specs, in controller specs I have a before(:each) which sets up things required in the session

my before filter is...

config.before(:each, :type => :controller) do

  ... 

  session[:current_user] = @user
  session[:instance] = @instance

  ...

end

@user and @instance are also set in the before(:each) i've just hidden them for readability here

I get the following error when running the controller tests

undefined method `session' for nil:NilClass

I would expect the global before callbacks to have the same things as the ones in the individual tests but I guess maybe they are loaded before the rails environment has been initialised?

Thanks

© Stack Overflow or respective owner

Related posts about ruby-on-rails-3

Related posts about rspec