控制器规范中的存根认证 - 映射

时间:2014-12-27 12:12:02

标签: ruby-on-rails rspec devise

我正在尝试遵循本指南https://github.com/plataformatec/devise/wiki/How-To:-Stub-authentication-in-controller-specs,但我有以下错误:

Could not find a valid mapping for #<RSpec::Mocks::Double:0x3fd34ba09afc @name=User(id: integer, email: string, encrypted_password: string, reset_password_token: string, reset_password_sent_at: datetime, remember_created_at: datetime, sign_in_count: integer, current_sign_in_at: datetime, last_sign_in_at: datetime, current_sign_in_ip: inet, last_sign_in_ip: inet, created_at: datetime, updated_at: datetime, name: string, company_id: string, phone: string, unit_id: integer, admin: boolean, invite_id: integer)>

帮助代码:

  def sign_in(user = double('user'))
    if user.nil?
      allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, {:scope => :user})
      allow(controller).to receive(:current_user).and_return(nil)
    else
      allow(request.env['warden']).to receive(:authenticate!).and_return(user)
      allow(controller).to receive(:current_user).and_return(user)
    end
  end

我的测试有:

before do
   sign_in
end

我做错了什么?

由于

0 个答案:

没有答案