Hi, I''m trying to test the behavior of a route with a delete method. Something like this: When "the admin clicks on ''delete''" do delete admin_blog_path(@blog) end which raises the following exception: NoMethodError: You have a nil object when you didn''t expect it! The error occurred while evaluating nil.env If I change the delete, for a get or a post it works like a charm. What am I missing here? Thanks in advance! Raimond Garcia
On Feb 4, 2008 6:54 AM, Raimond Garcia <voodoorai2000 at gmail.com> wrote:> Hi, > > I''m trying to test the behavior of a route with a delete method. > > Something like this: > When "the admin clicks on ''delete''" do > delete admin_blog_path(@blog) > end > > which raises the following exception: > NoMethodError: You have a nil object when you didn''t expect it! > The error occurred while evaluating nil.envCan you show the rest of the backtrace?> > > If I change the delete, for a get or a post it works like a charm. > > What am I missing here? > > Thanks in advance! > > > Raimond Garcia > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On 4.2.2008, at 14.54, Raimond Garcia wrote:> Hi, > > I''m trying to test the behavior of a route with a delete method. > > Something like this: > When "the admin clicks on ''delete''" do > delete admin_blog_path(@blog) > end > > which raises the following exception: > NoMethodError: You have a nil object when you didn''t expect it! > The error occurred while evaluating nil.env > > > If I change the delete, for a get or a post it works like a charm. > > What am I missing here?I would recommend against using the restful named routes in your stories. You want to test your full stack there, right, so just use the url. I also recommend using Webrat in conjunction with stories: http://www.benmabey.com/2008/02/04/rspec-plain-text-stories-webrat-chunky-bacon/ That way you are much more testing the behaviour of the application rather than its implementation. If you only want to test that the route is working, it would imho belong to the controller specs, not to the stories. Cheers, //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi
On Feb 4, 2008 6:54 AM, Raimond Garcia <voodoorai2000 at gmail.com> wrote:> Hi, > > I''m trying to test the behavior of a route with a delete method. > > Something like this: > When "the admin clicks on ''delete''" do > delete admin_blog_path(@blog) > end > > which raises the following exception: > NoMethodError: You have a nil object when you didn''t expect it! > The error occurred while evaluating nil.envCan you show the rest of the backtrace? Sure, I''m using rspec 1.1.2, the backtrace is nice and clean, to get the following, I commented out all the IGNORE_PATTERS, there is probably a better way of doing it, but it worked. NoMethodError: You have a nil object when you didn''t expect it! The error occurred while evaluating nil.env /Users/raimondgarcia/Documents/workspace/breport.git/config/../ vendor/rails/actionpack/lib/action_controller/test_process.rb:352:in `delete'' ./stories/steps/blog_steps.rb:10:in `the admin clicks on ''delete'''' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ step.rb:16:in `__send__'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ step.rb:16:in `perform'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ world.rb:73:in `store_and_call'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ world.rb:110:in `When'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ runner/story_mediator.rb:115:in `send'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ runner/story_mediator.rb:115:in `to_proc'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ runner/story_mediator.rb:95:in `instance_eval'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ runner/story_mediator.rb:95:in `to_proc'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ runner/story_mediator.rb:95:in `each'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ runner/story_mediator.rb:95:in `to_proc'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ runner/scenario_runner.rb:14:in `instance_eval'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ runner/scenario_runner.rb:14:in `run'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ runner/story_runner.rb:48:in `run_stories'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ runner/story_runner.rb:44:in `each'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ runner/story_runner.rb:44:in `run_stories'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ runner/story_runner.rb:39:in `each'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ runner/story_runner.rb:39:in `run_stories'' /Users/raimondgarcia/Documents/workspace/breport.git/config/../vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/ runner.rb:46:in `register_exit_hook'' stories/user_blogs.rb:4 Thanks, Raimond Garcia> > > If I change the delete, for a get or a post it works like a charm. > > What am I missing here? > > Thanks in advance! > > > Raimond Garcia-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080204/52717d1d/attachment.html
On Feb 4, 2008 10:49 AM, Raimond Garcia <voodoorai2000 at gmail.com> wrote:> > On Feb 4, 2008 6:54 AM, Raimond Garcia <voodoorai2000 at gmail.com> wrote: > Hi, > > I''m trying to test the behavior of a route with a delete method. > > Something like this: > When "the admin clicks on ''delete''" do > delete admin_blog_path(@blog) > end > > which raises the following exception: > NoMethodError: You have a nil object when you didn''t expect it! > The error occurred while evaluating nil.env > > Can you show the rest of the backtrace? > > Sure, I''m using rspec 1.1.2, the backtrace is nice and clean, to get the > following, I commented out all the IGNORE_PATTERS, there is probably a > better way of doing it, but it worked.Sorry, but I can''t really see anything related to rspec from the backtrace. I changed to a named route in one of my own steps and it worked fine. Can you try doing this in a rails integration test and see if you have a different result?
> > On 4.2.2008, at 14.54, Raimond Garcia wrote: > >> Hi, >> >> I''m trying to test the behavior of a route with a delete method. >> >> Something like this: >> When "the admin clicks on ''delete''" do >> delete admin_blog_path(@blog) >> end >> >> which raises the following exception: >> NoMethodError: You have a nil object when you didn''t expect it! >> The error occurred while evaluating nil.env >> >> >> If I change the delete, for a get or a post it works like a charm. >> >> What am I missing here? > > I would recommend against using the restful named routes in your > stories. You want to test your full stack there, right, so just use > the url. I also recommend using Webrat in conjunction with stories: http://www.benmabey.com/2008/02/04/rspec-plain-text-stories-webrat-chunky-bacon/ > > That way you are much more testing the behaviour of the application > rather than its implementation. > > If you only want to test that the route is working, it would imho > belong to the controller specs, not to the stories. > > Cheers, > //jarkko > > -- > Jarkko Laine > http://jlaine.net > http://dotherightthing.com > http://www.railsecommerce.com > http://odesign.fiInteresting Jarkko... The restful routes, seem clearer than using urls, maybe not so much for this case, but for very long urls, that include for example the title of a blog, I would rather use blog_path(@blog). Yes, I want to test the full stack, for sure! However, I don''t see how using named routes, stops you from doing this.... Webrat two thumbs up, I''ve been using selenium up to now, but would like to try other alternatives to see which one works better. Regards, Raimond Garcia P.S. This message is repeated with the wrong subject somewhere in the mailing list, sorry about that ;-|
>> Hi, >> >> I''m trying to test the behavior of a route with a delete method. >> >> Something like this: >> When "the admin clicks on ''delete''" do >> delete admin_blog_path(@blog) >> end >> >> which raises the following exception: >> NoMethodError: You have a nil object when you didn''t expect it! >> The error occurred while evaluating nil.env >> >> Can you show the rest of the backtrace? >> >> Sure, I''m using rspec 1.1.2, the backtrace is nice and clean, to >> get the >> following, I commented out all the IGNORE_PATTERS, there is >> probably a >> better way of doing it, but it worked. > > Sorry, but I can''t really see anything related to rspec from the > backtrace. I changed to a named route in one of my own steps and it > worked fine. Can you try doing this in a rails integration test and > see if you have a different result? >Will do. Thanks for the fast replies!> > ------------------------------
On 4.2.2008, at 19.16, Raimond Garcia wrote:> Interesting Jarkko... > > The restful routes, seem clearer than using urls, maybe not so much > for this case, but for very long urls, that include for example the > title of a blog, I would rather use blog_path(@blog). > > Yes, I want to test the full stack, for sure! However, I don''t see how > using named routes, stops you from doing this.... > > Webrat two thumbs up, I''ve been using selenium up to now, but would > like to try other alternatives to see which one works better.What I mean by testing the full stack is that you''d e.g. have this in your story: clicks_button "Delete" If you just use "delete some_url", there are two things that could be missed: 1) You have forgotten the DELETE method from your delete button. 2) The actual url in the form doesn''t actually point to some_url. Neither of the two would be caught unless you used something like Webrat to drill through the whole stack. If you''re using blog_path in the story, I feel like you''re using the route to test itself. Cheers, //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi
> > On 4.2.2008, at 19.16, Raimond Garcia wrote: >> Interesting Jarkko... >> >> The restful routes, seem clearer than using urls, maybe not so much >> for this case, but for very long urls, that include for example the >> title of a blog, I would rather use blog_path(@blog). >> >> Yes, I want to test the full stack, for sure! However, I don''t see >> how >> using named routes, stops you from doing this.... >> >> Webrat two thumbs up, I''ve been using selenium up to now, but would >> like to try other alternatives to see which one works better. > > What I mean by testing the full stack is that you''d e.g. have this in > your story: > > clicks_button "Delete" > > If you just use "delete some_url", there are two things that could be > missed: > > 1) You have forgotten the DELETE method from your delete button. > 2) The actual url in the form doesn''t actually point to some_url. > > Neither of the two would be caught unless you used something like > Webrat to drill through the whole stack. If you''re using blog_path in > the story, I feel like you''re using the route to test itself. > > Cheers, > //jarkko > > -- > Jarkko Laine > http://jlaine.net > http://dotherightthing.com > http://www.railsecommerce.com > http://odesign.fi >Excellent observations Jarkko! I''m still trying to get my head around the concept of "testing the full stack" and you just enlightened me a little more. Thanks! Rai