Factory girl sometimes breaks migrations in the test environment.
I found it's necessary to avoid the default naming scheme (spec/factories.rb etc), and add a "require 'spec/xfactory.rb'"line at the end of spec_helper.rb.
Otherwise, the migrations do not take place when I run rake db:test:prepare.
Can you include the version of Rails and factory_girl you're using, as well as the error you're seeing? It seems likely that this is a load order issue, so your factories file would be useful as well.
factory_girl (~> 1.3)
rails (>= 3.0.0.beta4)
Factory.define :user, :class => User do |usr|
Factory.define :anonymous_client, :class => Client do |cl|
If you're using Rails 3, you probably want to check out factory_girl_rails. I'm not sure how your definitions are being auto-loaded for a Rails 2 app - do you require factory_girl or the step definitions manually somewhere?
My instinct is that if you change all the literal class references (ie User) to be strings referring to class names (ie "User") your errors will go away.
Changing the classes to strings did fix it. Is it possible to get an error message when literal class references are passed in, or is there a valid use case for that?
Passing in class references works fine outside of Rails, and it works fine in Rails if you control your load order. Because Rails autoloads missing constants, the load order is more or less implicit in most Rails applications.
Fix DB migrations (factory_girl can break it)