I am pretty new to factory_girl and I have the following problem.
I have a class say of the form:
class Fruit::Apple < ActiveRecord::Base
...
end
Suppose I need to create factories for this class. How should I do it? In other words is there a set_fixture_class equivalent for factories?
My apple_factory.rb is as follows:
FactoryGirl.define do |f|
factory 'apple' do
variety : washington
end
end
I have all the required gems and my folder structure is of the form test/factory/apple_factory.rb
. When I execute my tests I get uninitialized constant Apple
. Where do I set the class definition? Do I need to set a factory helper?
So, in ruby privates classes can be defined inside a class as a sub-class and declaring them into privates constants, here this private class can be only accessed through the outer-class.
A Ruby module is nothing more than a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules.
Looks like you are using namespaces for your models.
Take a look at this question and answer: Using factory_girl_rails with Rspec on namespaced models
Factory.define :apple, :class => Fruit::Apple do |f|
f.variety 'Fuji'
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With