FactoryGirl + Shoulda NoMethodError:未定义的方法`featured ='

时间:2012-09-21 03:37:28

标签: ruby-on-rails rspec factory-bot shoulda

我有以下测试失败

2) Dvd when is featured 
   Failure/Error: subject { Factory(:featured) }
   NoMethodError:
     undefined method `featured=' for #<Dvd:0x007f9cdb50e400>
   # ./spec/models/dvd_spec.rb:25:in `block (3 levels) in <top (required)>'
   # ./spec/models/dvd_spec.rb:27:in `block (3 levels) in <top (required)>'

规范文件是以下

describe "when is featured" do 
  subject { Factory(:featured) }

  it { should validate_presence_of(:featured) }  
 end

和工厂

# This will guess the Dvd class
FactoryGirl.define do
  factory :dvd do
    title "DVD Test Title"
  end

  factory :featured, class: Dvd do
    title "DVD Title Featured"
    featured true
  end
end

DVD模型只是

class Dvd < ActiveRecord::Base

  attr_accessible :title, :featured

end

这是架构

create_table "dvds", :force => true do |t|
  ...
  t.boolean  "explicit",           :default => false
  t.boolean  "featured",           :default => false
end

知道是什么导致测试失败了吗?

0 个答案:

没有答案