Rspec测试设计具有抽象控制器错误的注册控制器

Rspec测试设计具有抽象控制器错误的注册控制器,rspec,devise,user-registration,Rspec,Devise,User Registration,Rspec配置 RSpec.configure do |config| config.include Devise::TestHelpers, :type => :controller ... 路线 devise_for :users, controllers: { passwords: "users/passwords", sessions: "users/sessions", registrations: "users/registrations"} 关于会话控制器 class

Rspec配置

RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller
...
路线

devise_for :users, controllers: { passwords: "users/passwords", sessions: "users/sessions", registrations: "users/registrations"}
关于会话控制器

class Users::SessionsController < Devise::SessionsController    
end
这次考试成功通过了!但是当我以同样的方式进行
RegistrationController
测试时,我得到了一个错误:

测试代码

require 'spec_helper'

describe Users::SessionsController do

controller do
  def after_sign_in_path_for(resource)
    super resource
  end
end

describe "After user sigin-in" do
  before(:each) do
    @user = FactoryGirl.create(:user)     
  end

  it "change current_user" do
    sign_in @user
    expect( subject.current_user ).to eq(@user)
  end

  it "redirects to the user_root_path" do
    user = FactoryGirl.create(:user)
    controller.after_sign_in_path_for(@user).should == root_path
  end
end
...
require 'spec_helper'

describe Users::RegistrationsController do

controller do
  def after_sign_up_path_for(resource)
    super resource
  end
end

describe "User sign_up" do  

it "change current_user" do
  post :create, user: FactoryGirl.attributes_for(:register_user)
  expect( subject.current_user ).not_to be nil
end
...
错误

用户::注册控制器用户注册更改当前用户
失败/错误:post:create,用户:FactoryGirl.attributes\u for(:register\u user)
AbstractController::ActionNotFound:
找不到匿名控制器的操作“创建”
#./spec/controllers/registrations\u controllers\u spec.rb:18:in'block(3级)in'

我对
*\u spec.rb
文件中的用户方法控制器犯了一些错误,它定义了一个从所描述的类继承的匿名控制器。通过在
spec\u helper.rb

config.infer_base_class_for_anonymous_controllers = false
您可以参考该链接了解更多信息

更好地显示您正在测试的控制器。我创建了自定义控制器,但没有更改或扩展任何控制器操作。
config.infer_base_class_for_anonymous_controllers = false