Hi! Another problem... I am using a model named "Factory" since the beginning of this project. Now I wanted to migrate my tests that depends on a manually seeded database over to factory_girl. In production I can still enter console or start the server, but when trying to do anything in test-env, then I get the following stacktrace: /home/nmelzer/Dokumente/sources/ruby/1.9.2/rails3.1/webworld/app/models/factory.rb:1:in `<top (required)>'': Factory is not a class (TypeError) from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `block in require'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:225:in `load_dependency'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:348:in `require_or_load'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:302:in `depend_on'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:214:in `require_dependency'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/engine.rb:416:in `block (2 levels) in eager_load!'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/engine.rb:415:in `each'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/engine.rb:415:in `block in eager_load!'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/engine.rb:413:in `each'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/engine.rb:413:in `eager_load!'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/application/finisher.rb:51:in `block in <module:Finisher>'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `instance_exec'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `run'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/initializable.rb:50:in `block in run_initializers'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `each'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `run_initializers'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/application.rb:92:in `initialize!'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/railtie/configurable.rb:30:in `method_missing'' from /home/nmelzer/Dokumente/sources/ruby/1.9.2/rails3.1/webworld/config/environment.rb:5:in `<top (required)>'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/application.rb:78:in `require'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/application.rb:78:in `require_environment!'' from /home/nmelzer/.rvm/gems/ruby-1.9.2-p180@webworld/gems/railties-3.1.0/lib/rails/commands.rb:39:in `<top (required)>'' from script/rails:6:in `require'' from script/rails:6:in `<main>'' This looks plausible to me. Since factory_girl provides a module Factory. But how can I avoid this problem, without completely rewriting all code that depends on my model? Or alternatively, are there any similar things like Factory_girl that will not have that collision with my own code? TIA Norbert -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2011/11/18 Norbert Melzer <timmelzer-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>:> But how can I avoid this problem, without completely rewriting all > code that depends on my model?I posted this on the github site also, there I was advised to use `::Factory` inside my code whenever I am refering my own model. Since this is a problem that occurs only in testenv, but I have to change my overall code, I dislike that solution, what brings me to...> Or alternatively, are there any similar things like Factory_girl that > will not have that collision with my own code?... another gem I stumbled upon yesterday, "Fabrication" (<http://fabricationgem.org/>). This does mostly the same as factory_girl does, and adds some spice. It is capable of generating cucumbersteps which makes creation of objects in my features a lot easier, also I can use properties of the fabricated model inside of the fabricator without to build them in a variable first (a thing I missed in factory girl) While I had to do following in FG Factory.define :user do |user| user_name = Factory.next(:name) # Just imagine I had used inlinesequence at this point :) user.name "#{user_name}" user.email "#{user_name}@example.com" user.password "secret" end I can do the following in Fabricatiion: Fabricator(:user) do name { sequence { |n| "User#{n}" } } email { |user| "#{user.name.downcase.parameterize}@example.com" } password "secret" end This is from a privat project, where I am converting my Factorys to Fabricators, also I converted all sequences to inline where possible (this is something I had done with FG soon too) I hope this one helps others too! Bye Norbert -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.