how to put debugger in factory girl?
Asked Answered
W

1

14

How do you debug factory_girl? i've tried to put debugger in there but i just cant. I just want to test why my associations aren't working right

Westernism answered 11/4, 2011 at 6:35 Comment(0)
L
5

How did you use the debugger? If you tried to use it in test environment, I'm not surprised it didn't work. But factory_girl is not limited to test environment.

Simply require factory_girl gem and relevant factories in development environment, start the server with debugger (or just console) and you're set for debugging.

UPDATE

I have this setup in https://github.com/lstejskal/icanhazblog. When you install it and run 'rails console', you can then do stuff like:

$ a = Factory.create :article
=> #<Article _id: 4dc27b867319e80fb2000001, created_at: 2011-05-05 10:27:18 UTC,
updated_at: 2011-05-05 10:27:18 UTC, title: "Article 1", content: "This is a content
for Article 1.", visible: true, published_at: 2011-02-11 23:00:00 UTC, tags: ["ruby",
"rails", "sinatra"]> 
$ a.title
=> "Article 1" 

Just add something like this when starting in development mode:

require 'factory_girl'
# require factories
Dir["#{PATH_TO_FACTORIES}/*.rb"].each { |f| require f }
Lavonia answered 4/5, 2011 at 11:30 Comment(10)
i tried putting the debugger in the factories themselves..where did you put yours?Westernism
I would start it with test environment like this: RAILS_ENV=test rails consoleSingletary
Make sure to reset your test database between each test: rake db:reset RAILS_ENV=testSingletary
I don't think that running rails console in test environment will work. That won't include test/test_helper.rb where the factories are usually set up.Lavonia
Thanks! Just to clarify, start script/console test, then paste the lines above under 'when starting in development mode', (edit as required). (Note, running Rails 2.3.5)Insipience
Yes. You can use any environment, but it will work in test just as well.Lavonia
NOTE: Instead of requiring the factories manually, you can also use FactoryGirl.find_definitions if your factories are in the default locations spec/factories or test/factories.Priestridden
Doesn't answer the question, how can I get interactive debugging inside my factory girl set up code (such as in an 'after_build'). Why shouldn't I want to do that?Tosch
Yea, putting a debugger into the factory is often the only way to debug e.g. odd interactions with activerecord callbacks. Whether you invoke it from a test or the console doesn't change the fact that often bugs occur inside the FactoryBot stack, which is "magic"ly buggy.Riffe
This doesn't really answer the question "how do I debug factories?"Engross

© 2022 - 2024 — McMap. All rights reserved.