ユーザーの作成をテストしようとしています。メッセージは、以下の2つの方法を提供しtest devise_token_auth:パス "/ api/v1/auth"のdeviseマッピングが見つかりませんでした
Failures:
1) DeviseTokenAuth::RegistrationsController Register a user request should be successful
Failure/Error: post :create, params:{email:"[email protected]",password:"123123",password_confirmation:"123123"}
AbstractController::ActionNotFound:
Could not find devise mapping for path "/api/v1/auth".
This may happen for two reasons:
1) You forgot to wrap your route inside the scope block. For example:
devise_scope :user do
get "/some/route" => "some_devise_controller"
end
2) You are testing a Devise controller bypassing the router.
If so, you can explicitly tell Devise which mapping to use:
@request.env["devise.mapping"] = Devise.mappings[:user]
# ./spec/controllers/devise_token_auth/registrations_controller_spec.rb:5:in `block (2 levels) in <top (required)>'
Finished in 0.01477 seconds (files took 1.76 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/controllers/devise_token_auth/registrations_controller_spec.rb:10 # DeviseTokenAuth::RegistrationsController Register a user request should be successful
: 1私はルートに最初を追加しようとしました)私は、私が得たテストを実行したときにここで
registrations_controller_spec.rb
require 'rails_helper'
RSpec.describe DeviseTokenAuth::RegistrationsController, type: :controller do
before :each do
post :create, params:{email:"[email protected]",password:"123123",password_confirmation:"123123"}
@data = JSON.parse(response.body)
end
describe "Register a user" do
it "request should be successful" do
expect(response).to have_http_status(200)
end
end
end
ですしかし、私はそれをどこに追加すればよいのでしょうか? 2)ブロック前に@request.env["devise.mapping"] = Devise.mappings[:user]
を追加しましたが、機能しません。
これをどのように解決する必要がありますか?ありがとうございました!
ここでは、コンソールでの私のroutes.rbを
Rails.application.routes.draw do
namespace :api do
scope :v1 do
mount_devise_token_auth_for 'User', at: 'auth'
end
end
end