disable factory model generator #62

wants to merge 1 commit into


None yet

10 participants


can disable factories from being generated

config.generators do |g|
  g.factories false
@brewster1134 brewster1134 factories generator
can disable factories from being generated

config.generators do |g|
  g.factories false

What's the use of this option? Why would someone run the generators if they didn't want it to generate code?

Also you're missing a test-driven implementation, as well as a test-driven implementation for the Test::Unit case.


using rspec I typically keep my factories defined in spec/factories.rb rather than in individual files in spec/factories/foo.rb. when generating a rails model, the factory girl generator is invoked and the individual file is created. I would have to remember to delete it otherwise there are errors about the factory already being defined. its nice having the the option to disable it so only the model and rspec files are generated.

and sorry about the lack of tests. im surprised i did that actually. sometimes im spaced out when im working. i will add those unless its decided this feature unwanted.


@joshuaclayton @jferris @brewster1134 how about this idea: if spec/factories.rb exists, don't generate anything; otherwise, generate the spec/factories/foo.rb stub.

Or should we generate anything at all?

jferris commented Jun 20, 2012

It makes the most sense to me to not generate anything at all when that option is set.


@mike-burns I personally would prefer an explicit declaration for generating factories along with models / resources.

The conditional check for factories.rb could lead to some confusing behavior for someone unfamiliar with this change.


This is a good idea. I also use factories.rb and the generator has been causing a lot of errors in production because I don't realize there is a duplicate factory until deployment. I've tried disabling the generator from application.rb file, but didn't seem to work.


@tenaciousflea setting the factories generator to false will only work if you are using my fork (https://github.com/brewster1134/factory_girl_rails) or once the pull request is approved.

mateusg commented Sep 19, 2012

Any news on this issue?
I agree with @joshmattvander. The automatic check for factories.rb could be confusing for those who are not familiar with this behaviour.
Could you please add the tests to the pull request, @brewster1134?

fzf commented Dec 5, 2012

Can we pull this in, it seems like a pretty straightforward request and should not affect anyones current configuration.



Is there something that I can help to get this issue into being merged into master?


@oogabooga if you wanted to write a test for this I think it may get merged. This has been on my to-do list for a long time now but I have been hard-pressed for time. I apologize.

Iazel commented Feb 19, 2013

Also the method used in generators set up is still too forced. For example, if I want to use a different fixture_replacement with a test_framework != rspec, it's not possibile, because it's automatically set in the initializer.

Disabling through g.factories false is the best option.

EDIT: I've just seen the commit, it's not perfect. IMHO, it should be:

next if rails_option[:factory_girl] == false

At line 10.


I think this feature is already implemented. If you don't want any factories to be generated just do this in your config:

config.generators do |g|
  g.test_framework :rspec, fixture_replacement: false

or even easier, you can just move factory_girl_rails out of the development group in your Gemfile.

What it would actually be nice in my opinion is to have the default factory generated where you expect, either appended to spec/factories.rb or in its own file in spec/factories

@joshuaclayton joshuaclayton added a commit that closed this pull request Apr 5, 2013
@joshuaclayton joshuaclayton Break generator up for separate frameworks
Closes #91, Closes #62
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment