views:

604

answers:

2

Hi there, Given I have a named route:

map.some_route '/some_routes/:id', :controller => 'some', :action => 'other'

How do I use the routing spec file 'spec/routing/some_routing_spec.rb' to test for that named route?

I've tried this after the "describe SomeRouteController" block and it doesn't work, I get 'undefined method "helper":

describe SomeRouteHelper, 'some routes named routes' do
  it 'should recognize some_route' do
    helper.some_route_path(23).should == '/some_routes/23'
  end
end
+1  A: 

You can do this in your controller specs with the assert_routing method, like so:

describe UsersController do
  it "should recognize a specific users#show route" do
    assert_routing("/users/23", {:controller => "users", :action => "show", :id => 23})
  end
end

More documentation is here.

bantic
Yup, that's for regular route recognition, I was looking for named route specs though. Thanks though!
btelles
+1  A: 

If this is in a controller spec, you can call the routing method directly, no helper needed.

describe SomeController do
  it 'should recognize ma routes!' do
   thing_path(23).should == '/things/23'
  end
end
Baldu
Thanks, I tried that as well, just wanted to hear someone else say I wasn't crazy, hehe...Turns out I had used nested resources, which requires the parent_child_path(23) format as opposed to the child_path(23) format.
btelles