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版本。 –