I have been trying to use FactoryGirl while developing a Rails 3 mountable engine, and when the factory is called in the spec, it returns the following error:
NoMethodError: undefined method `foo_bar=' for #<Foo::Baz:0x007fed6e3e2700>
Models
Foo::Bar
module Foo
class Bar < ActiveRecord::Base
has_many :bazs
end
end
Foo::Baz
module Foo
class Baz < ActiveRecord::Base
belongs_to :bar
end
end
Factories
FactoryGirl.define do
factory :foo_bar, class: Foo::Bar do
...
end
factory :foo_baz, class: Foo::Baz do
foo_bar
end
end
Looking at other topics FactoryGirl + RSpec + Rails 3 ‘undefined method =’ and followed the answer and it still did not work.
Any ideas on how to solve this?
The problem was caused by the calling create from FactoryGirl using the wrong association name in my spec.
With the help that jimworm provided, it pointed me to look at the spec, so I modified the call shown below.
This fixed the issue.
Thank you, jimworm for your help.