views:

2564

answers:

3

The background: I'm having some problems with Thoughtbot's "Factory Girl" gem, with is used to create objects to use in unit and other tests. I'd like to go to the console and run different Factory Girl calls to check out what's happening. For example, I'd like to go in there are do...

>> Factory(:user).inspect

I know that you can run the console in different environments...

$ script/console RAILS_ENV=test

But when I do that, Factory class is not available. It looks as though test_helper.rb is not getting loaded.

I tried various require calls including one with the absolute path to test_helper.rb but they fail similarly to this:

$ script/console RAILS_ENV=test
>> require '/Users/ethan/project/contactdb/test/test_helper.rb'
  Errno::ENOENT: No such file or directory - 
  /Users/ethan/project/contactdb/config/environments/RAILS_ENV=test.rb

Grr. Argh.

+5  A: 

Run script/console --help. You'll notice that the syntax is script/console [environment], which in your case is script/console test.

I'm not sure if you have to require the test helper or if the test environment does that for you, but with that command you should at least be able to boot successfully into the test env.

As a sidenote: It is indeed kind of odd that the various binaries in script/ has different ways of setting the rails environment.

August Lilleaas
+1  A: 

Make sure you installed the GEM and you added the following line either in your environment.rb or test.rb file.

config.gem "thoughtbot-factory_girl", :lib => "factory_girl", :source => "http://gems.github.com"
Simone Carletti
+2  A: 
script/console test

Should be all you need.

David Smith