gpt4 book ai didi

ruby-on-rails - 运行 RSpec 测试时出现 UrlGenerationError

转载 作者:行者123 更新时间:2023-11-28 20:01:07 25 4
gpt4 key购买 nike

我正在尝试运行一个测试,以确保我的 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

关于ruby-on-rails - 运行 RSpec 测试时出现 UrlGenerationError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31543581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com