[rspec-users] undefined method `route_for

David Chelimsky dchelimsky at gmail.com
Tue Nov 10 09:59:25 EST 2009


On Tue, Nov 10, 2009 at 4:44 AM, Amit Kulkarni <lists at ruby-forum.com> wrote:

> Hi all,
> I am writing scenarios for testing my routes but it is giving me error
> as undefined method `route_for and also for params_from.
> Did i miss something which i need to add in my controller
>
> My code is as follows:
>
> require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
>
> describe HomeController, "routes" do
>  describe "route generation" do
>    it "should map { :controller => 'home', :action => 'index' } to
> /home" do
>      route_for(:controller => 'home', :action => 'index').should ==
> '/home'
>    end
>
>    it "should map { :controller => 'home' } RESTfully" do
>      params_from( :get, '/home' ).should == { :controller => 'home',
> :action => 'index' }
>    end
>  end
> end
>

route_to, route_for and params_from are all available in controller specs,
which are identified by:

1. spec/controllers in their path (i.e. spec/controllers/foo_controller_spec

2. describe "route generation", :type => :controller do

If neither of those cases is true, then you won't have access to the right
helpers and matchers.

HTH,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091110/4c8d37fc/attachment.html>


More information about the rspec-users mailing list