ruby > thoughts.find_all(&:sfw?).to_blog
 => #<URI::HTTP:0x00001 URL: http://MichaelXavier.net >
ruby > MichaelXavier.info
 =>  [ GitHub , Resume , Email ]
ruby > _

factory_girl on Rails 3: undefined method config
04|08|2010 — 1 comments  

Categories: rails, rails3, factory_girl

After upgrading to Rails 3 beta2 I started getting an error (undefined method config for NilClass) when running specs or tests using factory_girl.

This issue with factory_girl is is documented on the factory_girl github here. The issue occurs with a check at the end of factory_girl.rb. It currently reads "if defined? Rails.configuration" but should read "if defined? Rails.configuration and Rails.application". Unfortunately the thoughtbot team has not gotten around to fixing it so to solve it for now:

Edit your Gemfile thusly:


                  group(:test) do
                    gem 'factory_girl', :git => 'git://github.com/danielb2/factory_girl'
                  end
                  

This will source danielb2's fork which removes all the special setup for rails.

Next, edit your 'spec_helper' and add:


                  require 'factories'
                  

The offending file automatically required my spec/factories.rb file so it's no big deal to add this in manually.

Comments Comments RSS Feed

# 1
Mario wrote on 04|30|2010 :

Thanks for posting this. Saved me tons of time trying to figure it out!

Add Comment

(required)
(required, won't be displayed)

(Use Markdown syntax)