我正在使用Devise将用户登录到该应用程序。 我试图通过以下测试。名字和姓氏通过,但“expect(User.new).to_not be_admin”未通过。 每次我收到如下信息。
“失败/错误:期望(User.new).to_not be_admin期望#回应'admin?'”
有关如何通过此类测试的任何建议吗?我认为问题在于to_not be_admin - 但我对测试软件并不熟悉。我用谷歌搜索了但没有结果。非常感谢您的帮助。
规格/模型/ user_spec.rb
require 'spec_helper'
describe User do
it { should validate_presence_of (:firstname) }
it { should validate_presence_of (:lastname) }
it "by default isn't admin" do
expect(User.new).to_not be_admin
end
end
用户模型(User.rb):
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :reviews
has_many :products
validates_presence_of :firstname
validates_presence_of :lastname
end
我的用户表如下所示:
create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "firstname"
t.string "lastname"
t.boolean "admin", default: false
end