Nasir Jamal
2012-Apr-17 19:30 UTC
[rspec-users] Access controller object in controller macro
Hi We have just upgraded our Rails 2.3.11 app to Rails 3.0.0 and Rspec 1.3.2 to 2.6. We are having two problems with rspec currently and any help would be great. 1) We have some controller macros where we have been using the controller object, session hash, response, etc. in different methods for e.g. module ControllerMacros ? def imaginary_method_with_example_calls ???? # in actual code different methods call one of the below, this is just an example of things not working ? ? controller.stubs(:method) ??? controller.class.skip_before_filter(:name) ??? session[:user_id] = user.id ??? response.something ? end end But now after upgrading to Rspec 2.6 they do not work and calling controller just returns nil and hence undefined method ''skip_before_filter'' for NilClass error. I did google but found nothing regarding this. 2) Changing ''request.request_uri'' to ''request.full_path'' raises the following error when running rspec NoMethodError: ?????? undefined method `full_path'' for #<ActionController::TestRequest:0x1bfa46f8> Any help / suggestion would be really helpful. Kind regards, Nas -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120417/2aa20098/attachment.html>
Justin Ko
2012-Apr-18 08:34 UTC
[rspec-users] Access controller object in controller macro
On Apr 17, 2012, at 1:30 PM, Nasir Jamal wrote:> > Hi > > We have just upgraded our Rails 2.3.11 app to Rails 3.0.0 and Rspec 1.3.2 to 2.6. We are having two problems with rspec currently and any help would be great. > > 1) We have some controller macros where we have been using the controller object, session hash, response, etc. in different methods for e.g. > > module ControllerMacros > def imaginary_method_with_example_calls > # in actual code different methods call one of the below, this is just an example of things not working > controller.stubs(:method) > controller.class.skip_before_filter(:name) > session[:user_id] = user.id > response.something > end > end > > But now after upgrading to Rspec 2.6 they do not work and calling controller just returns nil and hence undefined method ''skip_before_filter'' for NilClass error. I did google but found nothing regarding this. > > 2) Changing ''request.request_uri'' to ''request.full_path'' raises the following error when running rspec > NoMethodError: > undefined method `full_path'' for #<ActionController::TestRequest:0x1bfa46f8> > > Any help / suggestion would be really helpful. > > Kind regards, > > Nas > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersI assume your app directory looks like this? app_root/spec/controllers/my_controller_spec.rb And you are running the specs from the *app_root*? How are you including this module? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120418/9a6ff034/attachment-0001.html>
Nasir Jamal
2012-Apr-18 08:59 UTC
[rspec-users] Access controller object in controller macro
Hi Justin Yes, the specs are in app_root/spec/controllers/ and we running the specs from app_root. We are including the macros like so: RSpec.configure do |config| ??? config.include(ControllerMacros, :type => :controller) end Kind regards, Nas ________________________________ From: Justin Ko <jko170 at gmail.com> To: Nasir Jamal <nas35_in at yahoo.com>; rspec-users <rspec-users at rubyforge.org> Sent: Wednesday, 18 April 2012, 9:34 Subject: Re: [rspec-users] Access controller object in controller macro On Apr 17, 2012, at 1:30 PM, Nasir Jamal wrote:>Hi > >We have just upgraded our Rails 2.3.11 app to Rails 3.0.0 and Rspec 1.3.2 to 2.6. We are having two problems with rspec currently and any help would be great. > >1) We have some controller macros where we have been using the controller object, session hash, response, etc. in different methods for e.g. > >module ControllerMacros >? def imaginary_method_with_example_calls >???? # in actual code different methods call one of the below, this is just an example of things not working >? ? controller.stubs(:method) >??? controller.class.skip_before_filter(:name) >??? session[:user_id] = user.id >??? response.something >? end >end > >But now after upgrading to Rspec 2.6 they do not workand calling controller just returns nil and hence undefined method ''skip_before_filter'' for NilClass error. I did google but found nothing regarding this.> >2) Changing ''request.request_uri'' to ''request.full_path'' raises the following error when running rspec >NoMethodError: >?????? undefined method `full_path'' for #<ActionController::TestRequest:0x1bfa46f8> > >Any help / suggestion would be really helpful. > >Kind regards, > >Nas >_______________________________________________ >rspec-users mailing list >rspec-users at rubyforge.org >http://rubyforge.org/mailman/listinfo/rspec-usersI assume your app directory looks like this? app_root/spec/controllers/my_controller_spec.rb And you are running the specs from the *app_root*? How are you including this module? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120418/54b92eff/attachment.html>
David Chelimsky
2012-Apr-18 12:42 UTC
[rspec-users] Access controller object in controller macro
On Tuesday, April 17, 2012 at 2:30 PM, Nasir Jamal wrote:> > Hi > > We have just upgraded our Rails 2.3.11 app to Rails 3.0.0 and Rspec 1.3.2 to 2.6. We are having two problems with rspec currently and any help would be great. > > 1) We have some controller macros where we have been using the controller object, session hash, response, etc. in different methods for e.g. > > module ControllerMacros > def imaginary_method_with_example_calls > # in actual code different methods call one of the below, this is just an example of things not working > controller.stubs(:method) > controller.class.skip_before_filter(:name) > session[:user_id] = user.id > response.something > end > end > > But now after upgrading to Rspec 2.6 they do not work and calling controller just returns nil and hence undefined method ''skip_before_filter'' for NilClass error. I did google but found nothing regarding this.Is imaginary_method_with_example_calls called in a config.before hook? If so, the issue is that controller is nil [1]. This has been fixed on master, but not yet released (look for the 2.10 release in the next couple of weeks.> 2) Changing ''request.request_uri'' to ''request.full_path'' raises the following error when running rspec > NoMethodError: > undefined method `full_path'' for #<ActionController::TestRequest:0x1bfa46f8>I''d check the rails docs for this one. I''m not immediately familiar w/ what''s going on. HTH, David [1] https://github.com/rspec/rspec-rails/issues/391 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120418/f6a086f2/attachment.html>