nil)" />
开发者

Error in Factory_girl: NoMethodError: undefined method - rspec and rails 3.1.0

开发者 https://www.devze.com 2023-04-04 04:03 出处:网络
I am having a problem with factory_girl. Here is the error with rspec. \"Failure/Error: customer = Factory(:customer, :name => nil)

I am having a problem with factory_girl. Here is the error with rspec.

"Failure/Error: customer = Factory(:customer, :name => nil) NoMethodError: undefined method `category1_id=' for #Customer:0x4175418"

Here is the rspec code:

describe "data integrity" do
  it "should return error with no name" do
    customer = Factory(:customer, :name => nil)
    customer.errors[:name].should_not be_empty
    customer.should_not be_valid
  end
  it "should take a good name" do
    customer = Factory(:customer, :name => "good customer name")
    customer.errors[:name].should be_empty
  end
end

category1_id is a column in customer table. Here is the customer.rb

class Customer < ActiveRecord::Base
  validates :name, :presence => true
end

The definition for Fac开发者_运维问答tory(:customer)

Factory.define :customer do |c|
  c.name "test customer"
  c.email "t@acom.com"
  c.phone "12345678"
  c.cell "1234567890"
  c.active 1
  c.category1_id 2
  c.short_name "test" 
end

Any thoughts? thanks.


The problem disappeared after the dependency on factory_girl_rails (by factory_girl) was dropped and Factory() was replaced with Factory.build().

Somehow factory_girl developed dependency on factory_girl_rails in my system (still don't know why). With factory_girl installed, gem check required factory_girl_rails to be installed. However when both factory_girl and factory_girl_rails installed, they generated conflict with duplicate error. After hours of failed tries, the conflict dependency mysteriously disappeared after rebooting and reloading the system.

0

精彩评论

暂无评论...
验证码 换一张
取 消