3

I'm trying to run a test that ensures my show template is rendered for a restaurant. After running the test I get:

 1) RestaurantsController GET #show 
     Failure/Error: before { get :show }
     ActionController::UrlGenerationError:
       No route matches {:action=>"show", :controller=>"restaurants"}

Not sure why its saying when there is indeed a route for showing restaurants:

    restaurants GET    /restaurants(.:format)          restaurants#index
                POST   /restaurants(.:format)          restaurants#create
 new_restaurant GET    /restaurants/new(.:format)      restaurants#new
edit_restaurant GET    /restaurants/:id/edit(.:format) restaurants#edit
     restaurant GET    /restaurants/:id(.:format)      restaurants#show
                PATCH  /restaurants/:id(.:format)      restaurants#update
                PUT    /restaurants/:id(.:format)      restaurants#update
                DELETE /restaurants/:id(.:format)      restaurants#destroy

Test

require "rails_helper"

describe RestaurantsController do
  describe "GET #show" do
    before { get :show }

    it { should render_template("show") }
  end
end
Carl Edwards
  • 13,826
  • 11
  • 57
  • 119

1 Answers1

0

You forgot the id

before { get :show, id: 1 } # Assuming there is a Restaurant with id=1
Mario Pérez Alarcón
  • 3,468
  • 2
  • 27
  • 38
  • Wow I'm surprised that they didn't include this in the Shoulda Matcher documentation (they only provide `get :show`). Do I need create a factory for this because at this point I get `ActiveRecord::RecordNotFound: Couldn't find Restaurant`? – Carl Edwards Jul 21 '15 at 15:52
  • Yup! You could do `Restaurant.create.id` to see if the test passes. But use factories! – Mario Pérez Alarcón Jul 21 '15 at 16:00