运行 RSpec 测试时的 UrlGenerationError
UrlGenerationError when running RSpec Test
我正在尝试 运行 一项测试,以确保我的 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
我正在尝试 运行 一项测试,以确保我的 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