Routing specs should test that the action (get
) given a path as a string (i.e. "/first/1/second/2") will route to an action with the correct parameters set (i.e. first_id: 1, id: 2
)
You don't need to create an instance of your models here. It's unnecessary and it'll just slow down the spec.
describe MenusController do
describe 'routing' do
it 'routes to #index' do
get('/restaurants/42/menus').should route_to('menus#index', restaurant_id: 42)
end
it 'routes to #show' do
get('/restaurants/42/menus/37').should route_to('menus#index', restaurant_id: 42, id: 37)
end
end
end
You can also pass in other arguments, like format: :json
, or anything else that might be gleaned from a URL string, as it's mainly testing that your routes file directs you to the correct place with the correct parameters.