FactoryGirl RSpec 创建工厂对象(其中工厂设置该对象的属性)时没有方法错误
每当我创建一个 Factory 对象时,当工厂在该对象上设置属性时,我都会收到此错误 - 在本例中为“名称”。为什么???
businesss.rb
FactoryGirl.define do
factory :business do
factory :business_main do
name "Dave's Toys"
end
end
end
企业表
Column | Type | Modifiers
----------------------+-----------------------------+---------------------------------------------------------
id | integer | not null default nextval('businesses_id_seq'::regclass)
name | character varying(255) |
address_line1 | character varying(255) |
address_line2 | character varying(255) |
city | character varying(255) |
state | character varying(255) |
zip | character varying(255) |
business_spec.rb
...
business = Factory(:business_main)
...
# Failure/Error: business = Factory(:business_main)
# NoMethodError: undefined method `name=' for #<Business:0x007fc991684590>
-
Using rails (3.1.3)
Using factory_girl (2.3.2)
Using factory_girl_rails (1.4.0)
Using rspec-core (2.7.1)
Using rspec-expectations (2.7.0)
Using rspec-mocks (2.7.0)
Using rspec (2.7.0)
Using rspec-rails (2.7.0)
Anytime I create a Factory object, I get this error where the factory sets a property on that object -- in this case 'name'. Why???
businesses.rb
FactoryGirl.define do
factory :business do
factory :business_main do
name "Dave's Toys"
end
end
end
businesses table
Column | Type | Modifiers
----------------------+-----------------------------+---------------------------------------------------------
id | integer | not null default nextval('businesses_id_seq'::regclass)
name | character varying(255) |
address_line1 | character varying(255) |
address_line2 | character varying(255) |
city | character varying(255) |
state | character varying(255) |
zip | character varying(255) |
business_spec.rb
...
business = Factory(:business_main)
...
# Failure/Error: business = Factory(:business_main)
# NoMethodError: undefined method `name=' for #<Business:0x007fc991684590>
-
Using rails (3.1.3)
Using factory_girl (2.3.2)
Using factory_girl_rails (1.4.0)
Using rspec-core (2.7.1)
Using rspec-expectations (2.7.0)
Using rspec-mocks (2.7.0)
Using rspec (2.7.0)
Using rspec-rails (2.7.0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
运行 rake db:test:clone ,然后所有测试数据库列将正确映射到 Active Record 方法。
Run
rake db:test:clone
and then all test DB columns will be mapped properly to Active Record methods.