0

我有一个使用 Sorcery(或尝试使用它)的应用程序,我正在为它编写规范:

context "successfull attempts to log in" do
  let(:attr) { attributes_for(:credentials) }

  before(:each) do
    @user = create(:user, attr)
  end

  it "should log the user in" do
    post :create, attr.merge(remember_me: false)
    controller.should be_logged_in
  end
end

这是 FactoryGirl 工厂:

FactoryGirl.define do
  factory :user do
    email                 Faker::Internet.safe_email
    password              "password"
    password_confirmation { |u| u.password }
    client_id             1
  end

  factory :credentials, class: User do
    email       "user@example.com"
    password    "password"
  end
end

这是控制器动作:

class SessionsController < ApplicationController
  # ...
  def create
    login(params[:email], params[:email], params[:remember_me])
    flash.now[:error] = "Invalid email/password combination"
    render :new
  end
end

错误消息如下:

1) SessionsController POST 'create' successfull attempts to log in should log the user in
     Failure/Error: controller.should be_logged_in
       expected logged_in? to return true, got false
     # ./spec/controllers/sessions_controller_spec.rb:54:in `block (4 levels) in <top (required)>'

由于某种原因,规范不断失败。谁能给我解释一下为什么?

4

1 回答 1

1

您的控制器使用电子邮件作为用户名和密码,这看起来像是复制和粘贴错误。那是对的吗?

于 2012-10-18T16:13:52.370 回答