我正在尝试运行一个测试,以确保为餐厅呈现我的show
模板。运行测试后,我得到:
1) RestaurantsController GET #show
Failure/Error: before { get :show }
ActionController::UrlGenerationError:
No route matches {:action=>"show", :controller=>"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
测试
require "rails_helper"
describe RestaurantsController do
describe "GET #show" do
before { get :show }
it { should render_template("show") }
end
end
最佳答案
您忘记了id
before { get :show, id: 1 } # Assuming there is a Restaurant with id=1