Jeff DeanJeff Dean
Adding Routes for tests / specs with Rails 3
edit Posted by Jeff Dean on Saturday August 21, 2010 at 09:13PM

If you ever need to test an abstract base controller independently from any subclass, you'll likely need to add a route for your test. Here's one example of how to do this in Rails 3:

*UPDATE: * Thanks to the tip by Austin Putman I've updated the gist to include an example use of the excellent with_routing method.

Comments

  1. Austin Putman Austin Putman on August 22, 2010 at 10:52AM

    Nice technique for longer tests. For single tests, you can also use a with_routing block

  2. Jeff Dean Jeff Dean on August 22, 2010 at 11:10AM

    Thanks Austin! If I had known that it would have saved me a few hours. I've updated the post to show an example of how to reuse with_routing across multiple tests.

  3. Mike Gehard Mike Gehard on August 23, 2010 at 08:16AM

    Or take a look at the controller() method in rspec-rails2... http://pivotallabs.com/users/mgehard/blog/articles/1350-using-rspec2-to-test-rails3-applicationcontroller-functionality

  4. Jeff Dean Jeff Dean on August 23, 2010 at 11:40AM

    Very slick - thanks!