0
我有一個失敗的,由於沒有路由匹配的規格,下面是相關代碼:RSpec的無路由匹配 - 缺少必需的鍵:[:ID]
describe AdminController do
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
@admin = create(:admin)
@user = create(:user)
sign_in @admin, scope: :user
end
context "with admin user" do
describe "DELETE #destroy" do
it "deletes the contact" do
puts @user.inspect
expect{
delete admin_destroy_user_path, id: @user.id
}.to change(Profile, :count).by(-1)
end
錯誤:
AdminController with admin user DELETE #destroy deletes the contact
Failure/Error: delete admin_destroy_user_path, id: @user.id
ActionController::UrlGenerationError:
No route matches {:action=>"destroy", :controller=>"admin"} missing required keys: [:id]
路線:
admin_destroy_user DELETE /admin/:id(.:format) admin#destroy
我不知道我錯過了什麼,任何幫助將不勝感激!
您正在使用哪種版本的RSpec?你可能需要像這樣傳遞id:'delete admin_destroy_user_path,params:{id:@ user.id}'假設'@ user.id'實際返回一個值。 – mmichael
或者您可以使用'admin_destroy_user_path(@ user.id)' –
謝謝各位先生們,但這些工作都不成功,我使用params:選項得到相同的錯誤。如果我使用Igor的選項,我會得到「ActionController :: UrlGenerationError: 沒有路由匹配{:action =>」/ admin/2「,:controller =>」admin「}」我還使用RSpec 3.5.4版本。 –