Rob Aldred
2011-Jan-14 10:07 UTC
[rspec-users] session variable not available in global before(:each, :type => :controller)
Hi, I''m refactoring some specs, in controller specs I have a before(:each) which sets up things required in the session, wanted to avoid duplication and put the initial setup global for each controller spec 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 this 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 -- Rob Aldred Software Developer rob at stardotstar.com twitter: stardotstar 47 Newton Street, Manchester, M1 1FT T: +44 (0) 161 236 9740 ___________________________________________________ This email and any files or ideas transmitted within it are sent in confidence and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager at info at stardotstar.com
David Chelimsky
2011-Jan-17 18:06 UTC
[rspec-users] session variable not available in global before(:each, :type => :controller)
On Fri, Jan 14, 2011 at 4:07 AM, Rob Aldred <Rob.aldred at stardotstar.com> wrote:> Hi, I''m refactoring some specs, in controller specs I have a before(:each) which sets up things required in the session, wanted to avoid duplication and put the initial setup global for each controller spec > > 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 this 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?That''s correct. I think this is a bug. Please report to http://github.com/rspec/rspec-rails/issues. Thx, David