RSpec Test of Custom Devise Session Controller Fails with AbstractController::ActionNotFound

后端 未结 1 1644
悲&欢浪女
悲&欢浪女 2020-12-18 20:34

I am currently trying to test a custom Devise session controller with rspec. My controller looks like this:

class SessionsController < Devise::SessionsCon         


        
相关标签:
1条回答
  • 2020-12-18 20:56

    I finally fixed my problem by doing including the devise test helpers, calling the method setup_controller_for_warden in my test AND doing request.env["devise.mapping"] = Devise.mappings[:user]. Like so:

    require 'test_helper'
    
    class SessionsControllerTest < ActionController::TestCase
        include Devise::TestHelpers
    
        test "should reject invalid captcha" do
           setup_controller_for_warden
           request.env["devise.mapping"] = Devise.mappings[:user]
    
           get :new
    
           assert_response :success
       end
    end
    

    Not sure about your double render problem though, are you sure your supposed to call post :create then render? i'm not sure how rspec is supposed to work.

    0 讨论(0)
提交回复
热议问题