0

我有这个 adminuser 模型测试,我得到了这个结果和错误。有什么问题,我该如何解决它 admin_user_spec.rb

require 'spec_helper'

describe AdminUser do

  it { should allow_mass_assignment_of(:email) }
  it { should allow_mass_assignment_of(:password) }
  it { should allow_mass_assignment_of(:password_confirmation) }
  it { should allow_mass_assignment_of(:remember_me) }

end

结果:

1) AdminUser 
     Failure/Error: it { should allow_mass_assignment_of(:password) }
     NoMethodError:
       undefined method `allow_mass_assignment_of' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f8d58d5d3a0>
     # ./spec/models/admin_user_spec.rb:6:in `block (2 levels) in <top (required)>'

管理员用户.rb

class AdminUser < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable, :lockable and :timeoutable
  devise :database_authenticatable, :trackable

  # :timeoutable, :lockable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me

#  after_create { |admin| admin.send_reset_password_instructions }

  # def password_required?
  #   new_record? ? false : super
  # end

end
4

3 回答 3

0

我添加了

require 'shoulda/integrations/rspec2'

这高于

require 'rspec/rails'

spec_helper.rb和问题解决

于 2013-02-26T23:18:50.663 回答
0

试一下...

require 'spec_helper'

describe AdminUser do

  it { should allow_mass_assignment_of(:email) }
  it { should allow_mass_assignment_of(:password).as(:admin) }
  it { should allow_mass_assignment_of(:password_confirmation) }
  it { should allow_mass_assignment_of(:remember_me) }

end
于 2013-02-26T11:14:36.373 回答
0

尝试添加

require 'shoulda-matchers'
require 'shoulda/matchers/integrations/rspec'

在你的 spec_helper.rb 的顶部

于 2013-02-26T12:38:02.437 回答