Mitchell Gould
2009-Apr-06 13:36 UTC
setup method in functional tests and instance variables
I have the following in my functional test file. class UserControllerTest < ActionController::TestCase fixtures :users def setup @controller = UserController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new @invalid_user = user(:invalid_user) @valid_user = users(:valid_user) end def test_login_success @valid_user.screen_name end When I run a test that tries to use the @valid_user variable I get the following error. NoMethodError: You have a nil object when you didn''t expect it! The error occurred while evaluating nil.screen_name It seems that this class isn''t storing the instance variables in memory. Any ideas. Thanks in advance Mitch -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
David Knorr
2009-Apr-06 14:06 UTC
Re: setup method in functional tests and instance variables
On 6 Apr., 15:36, Mitchell Gould <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have the following in my functional test file. > > class UserControllerTest < ActionController::TestCase > fixtures :users > > def setup > @controller = UserController.new > @request = ActionController::TestRequest.new > @response = ActionController::TestResponse.new > @invalid_user = user(:invalid_user) > @valid_user = users(:valid_user) > end > > def test_login_success > @valid_user.screen_name > end > > When I run a test that tries to use the @valid_user variable I get the > following error. > > NoMethodError: You have a nil object when you didn''t expect it! > The error occurred while evaluating nil.screen_name > > It seems that this class isn''t storing the instance variables in memory. > > Any ideas. >The above should work just fine, given that you have a user fixture named ''valid_user''. Do you see something like this in test/fixtures/ users.yaml? valid_user: screen_name: xyz -- Best regards, David Knorr http://twitter.com/rubyguy> Thanks in advance > > Mitch > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mitchell Gould
2009-Apr-06 14:59 UTC
Re: setup method in functional tests and instance variables
David Knorr wrote:> On 6 Apr., 15:36, Mitchell Gould <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> � @valid_user = users(:valid_user) >> The error occurred while evaluating nil.screen_name >> >> It seems that this class isn''t storing the instance variables in memory. >> >> Any ideas. >> > > The above should work just fine, given that you have a user fixture > named ''valid_user''. Do you see something like this in test/fixtures/ > users.yaml? > > valid_user: > screen_name: xyz > > -- > Best regards, > David Knorr > http://twitter.com/rubyguyHI David This is my yaml valid_user: id: 1 screen_name: millikan email: ram-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org password: electron Now here is the weird thing. if I do the following in the actual test method def test_login_success @valid_user = users(:valid_user) @valid_user.screen_name end it works just fine. Its like I can''t access instance variables that run in the setup. Why would that be? For my units test I have a similar setup and it works no problem. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mitchell Gould
2009-Apr-06 15:18 UTC
Re: setup method in functional tests and instance variables
Just found the answer it''s worth noting that R2.0.2 subclasses ActionController::TestCase for functional tests (i.e. UserControllerTest), not ActiveSupport::TestCase. You need to explicitly change the skeleton test files for (user|spec|etc)_controller_test.rb files to subclass ActiveSupport::TestCase. So I had to change the test file skeleton class definition to ActiveSupport::TestCase from ActionController::TestCase works like a charm. Why don''t they fix this? Mitch -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
David Knorr
2009-Apr-07 15:36 UTC
Re: setup method in functional tests and instance variables
On 6 Apr., 17:18, Mitchell Gould <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Just found the answer > > it''s worth noting that R2.0.2 subclasses ActionController::TestCase > for functional tests (i.e. UserControllerTest), not > ActiveSupport::TestCase. You need to explicitly change the skeleton > test files for (user|spec|etc)_controller_test.rb files to subclass > ActiveSupport::TestCase. > > So I had to change the test file skeleton class definition to > > ActiveSupport::TestCase > > from > > ActionController::TestCase > > works like a charm. > > Why don''t they fix this?What do mean when saying "fix this". Did you run the rails:update rake task? -- Best regards, David Knorr. http://twitter.com/rubyguy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mitchell Gould
2009-Apr-08 02:04 UTC
Re: setup method in functional tests and instance variables
David Knorr wrote:> On 6 Apr., 17:18, Mitchell Gould <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> ActiveSupport::TestCase >> >> from >> >> ActionController::TestCase >> >> works like a charm. >> >> Why don''t they fix this? > > What do mean when saying "fix this". Did you run the rails:update rake > task? > > -- > Best regards, > David Knorr. > http://twitter.com/rubyguyI did run rails:update rake. And I updated rails. But even now when I run script/generate controller someController I have to edit the test file so that it is changed from ActionController::Testcase to ActiveSupport::TestCase. Should I update something else so I don''t have to do this everytime? And it does this only for the functionals not the unit test skeletons. Mitch -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
David Knorr
2009-Apr-11 09:24 UTC
Re: setup method in functional tests and instance variables
On 8 Apr., 04:04, Mitchell Gould <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> David Knorr wrote: > > On 6 Apr., 17:18, Mitchell Gould <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > >> ActiveSupport::TestCase > > >> from > > >> ActionController::TestCase > > >> works like a charm. > > >> Why don''t they fix this? > > > What do mean when saying "fix this". Did you run the rails:update rake > > task? > > > -- > > Best regards, > > David Knorr. > >http://twitter.com/rubyguy > > I did run rails:update rake. And I updated rails. But even now when I > run script/generate controller someController I have to edit the test > file so that it is changed from ActionController::Testcase to > ActiveSupport::TestCase. > > Should I update something else so I don''t have to do this everytime? And > it does this only for the functionals not the unit test skeletons.Did you upgrade to another version of Rails recently? -- Best regards, David Knorr http://twitter.com/rubyguy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mitchell Gould
2009-Apr-22 04:48 UTC
Re: setup method in functional tests and instance variables
David Knorr wrote:> On 8 Apr., 04:04, Mitchell Gould <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> >> I did run rails:update rake. �And I updated rails. �But even now when I >> run script/generate controller someController I have to edit the test >> file so that it is changed from ActionController::Testcase to >> ActiveSupport::TestCase. >> >> Should I update something else so I don''t have to do this everytime? And >> it does this only for the functionals not the unit test skeletons. > > Did you upgrade to another version of Rails recently? > > -- > Best regards, > David Knorr > http://twitter.com/rubyguyI am using rails 2.0.2. I have written the app with this. If I move up to another version my application does not work. What do you suggest I do? How can I move my app to say 2.3.2 and have it still work? Thanks -- Posted via http://www.ruby-forum.com/.
Milan Iliev
2009-May-06 17:10 UTC
Re: setup method in functional tests and instance variables
Mitchell, Sounds like you should maybe just bite the bullet and upgrade to 2.3.2 if that''s being an issue. When you say "If I move up to another version [of Rails], my application does not work", what do you mean? Can you provide specific errors? Best, Milan On Apr 22, 12:48 am, Mitchell Gould <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> David Knorr wrote: > > On 8 Apr., 04:04, Mitchell Gould <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > >> I did run rails:update rake. And I updated rails. But even now when I > >> run script/generate controller someController I have to edit the test > >> file so that it is changed from ActionController::Testcase to > >> ActiveSupport::TestCase. > > >> Should I update something else so I don''t have to do this everytime? And > >> it does this only for the functionals not the unit test skeletons. > > > Did you upgrade to another version of Rails recently? > > > -- > > Best regards, > > David Knorr > >http://twitter.com/rubyguy > > I am using rails 2.0.2. I have written the app with this. If I move up > to another version my application does not work. > > What do you suggest I do? How can I move my app to say 2.3.2 and have it > still work? > > Thanks > > -- > Posted viahttp://www.ruby-forum.com/.
Mitchell Gould
2009-May-15 09:20 UTC
Re: setup method in functional tests and instance variables
Milan Iliev wrote:> Mitchell, > > Sounds like you should maybe just bite the bullet and upgrade to 2.3.2 > if that''s being an issue. > > When you say "If I move up to another version [of Rails], my > application does not work", what do you mean? Can you provide specific > errors? > > > Best, > Milan > > On Apr 22, 12:48�am, Mitchell Gould <rails-mailing-l...@andreas-s.net>Just a quick reply. Two things: 1. How do I move my app to 2.3.2? Do I just change the configuration settings? 2. When I have done this in the past the application won''t start up meaning the server won''t launch. Thanks for your reply Mitch -- Posted via http://www.ruby-forum.com/.