thoughtbot/factory_girl_rails — Issue #43: No method error when creating factory object where factory sets a property of that object
Author: macmartine
Created: 2011-11-29 19:44:38+00:00
State: open

Anytime I create a Factory object, I get this error where the factory sets a property on that object -- in this case 'name'.

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 #

-

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)