Alex Rivera | Logout

Setup Factory Girl with Test::Unit and Shoulda

Asked 2009-07-21T15:38:18.363
16

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 
Edit
Report

2 Answers

2

I also managed to get rid of this issue by putting this line into my environment.rb:

config.gem "factory_girl", :source => "http://gemcutter.org"

Make also sure you have the latest gem:

Name changed from "thoughtbot-factory_girl" to "factory_girl", source changed from "http://gems.github.com" to "http://gemcutter.org".

answered 2009-12-18T09:59:35.100
0

I added require 'factory_girl' require File.dirname(FILE) + "/factories" to spec_helper.rb whiche helped, but then I rememberd Spork can sometimes ba a bit of a problem, so I restarted Spork without the require and then it worked fine.

answered 2011-09-19T14:50:48.367

Your Answer