I'm trying to set up Factory Girl with Test::Unit and Shoulda in Ruby on Rails. I have installed the gem, created my factory file under the test/factories directory, and created my spec file under the test/models directory. The current error I'm getting is 'ArgumentError: No such factory: test', which leads me to believe that the test_factory.rb file is not being loaded? Any idea as to what I should change?
Here are my files.
#test/factories/test_factory.rb
Factory.define :test do |t|
t.name 'test_spotlight'
t.label 'test spotlight label'
end
and
#test/modes/test_spec.rb
require 'test_helper'
require 'factory_girl'
class TestTest < Test::Unit::TestCase
def setup
@test = Factory.build(:test)
end
context "A test" do
should "save with the minimum requirements" do
assert @test.save
end
end
end
I've run into this problem on one of my projects too. I'm not sure precisely what's causing the initialization code to be skipped but you can force load the factory definitions like this:
require 'factory_girl'
Factory.find_definitions
Hope this helps.
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