Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Rails 3.0 generator inconsistency

#5796

I am trying create an app that has no DB backend.

I generated the app using

rails new myapp -T -O

The problem is when I create a controller

using

rails generate controller mycontroller

I see some test unit file being generated..

test/functional/home_controller_test.rb
test/unit/helpers/home_helper_test.rb

and therefore rake test causes the following error

./test/functional/home_controller_test.rb:1:in require': no such file to load -- test_helper (LoadError)

from ./test/functional/home_controller_test.rb:1
from /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load'
from /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
from /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each'
from /usr/lib/ruby/gems/1.8/ge

Is this the expected behavior? I believe if I skip test unit, I should never have any test unit file created, right?

Reported by manu · October 12th, 2010 @ 11:46 PM

State: stale
Milestone: 3.x
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Rob Zolkos
    Rob Zolkos

    I can confirm this behaviour.

    I agree that if a rails app is created with the -T option then the following should be injected into application.rb

    config.generators do |g|
       g.test_framework  nil
    end
    

    Then subsequent generators won't generate any test files.

    October 13th, 2010 @ 05:34 AM

  2. Ryan Bigg
    Ryan Bigg
    • State changed from new to incomplete
    • Importance changed from to Low

    Please submit a patch to fix this issue, along with tests.

    October 13th, 2010 @ 05:44 AM

  3. manu
    manu

    Why is this marked as incomplete? What else do you need? I can also show you how cucumber rails totally breaks in this case.

    October 13th, 2010 @ 04:38 PM

  4. Aditya Sanghi
    Aditya Sanghi

    The ticket is marked incomplete while it is awaiting patches to fix the problem. Feel free to submit a patch. If you dont want to or cant for some reason, let me know. Someone else might pick up the challenge.

    October 13th, 2010 @ 06:01 PM

  5. Rob Zolkos
    Rob Zolkos

    I'll have a swing at writing a patch. Before I do, is there any existing design decision that was made that causes rails generators to create test files if the rails app was created with -T, or is it a bug that needs fixing?

    October 14th, 2010 @ 05:28 AM

  6. Rob Zolkos
    Rob Zolkos

    Attached is patch and tests.

    if rails app is created with -T or --skip-test-unit then the application.rb will contain

    config.generators do |g|
    g.test_framework nil end

    which will then mean that any future generators will not generate any test files.

    October 14th, 2010 @ 02:20 PM

  7. Elad Meidar
    Elad Meidar

    Verified and Patch is working on stable,
    Just one thing: the patch adds a config.generators block, isn't there anything else that adds this block already and might cause more than 1 to appear in the final output?

    October 14th, 2010 @ 03:33 PM

  8. Rob Zolkos
    Rob Zolkos

    I searched through the source today and couldn't find anything else or anywhere else that adds this block into application.rb

    October 15th, 2010 @ 12:30 PM

  9. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    October 19th, 2010 @ 08:32 AM

  10. Aditya Sanghi
    Aditya Sanghi
    • State changed from incomplete to verified
    • Milestone set to 3.x
    • Assigned user set to José Valim

    October 19th, 2010 @ 12:26 PM

  11. José Valim
    José Valim

    It looks good, I will apply it during the next weeks. Anyone in mood for supplying a similar patch to ActiveRecord? If so, you can use add "config.generators.orm false" to config/application.rb instead of giving a block.

    Similarly, the previous patch could be using "config.generators.test_framework false", but I will handle that.

    October 19th, 2010 @ 12:41 PM

  12. Aditya Sanghi
    Aditya Sanghi
    • Tag set to appgenerator, patch, railties

    Adding patch to add config.generators.orm = false when skip active_record is given as per José's suggestion above.

    October 19th, 2010 @ 01:00 PM

  13. Rob Zolkos
    Rob Zolkos

    And here is patch to add config.generators.test_framework = false when skip_test_unit is given.

    That should save you some precious time José :)

    October 19th, 2010 @ 02:18 PM

  14. Rob Zolkos
    Rob Zolkos

    And here is the patch.

    October 19th, 2010 @ 02:55 PM

  15. Rob Zolkos
  16. Repository
    Repository
    • State changed from verified to resolved

    (from [bafa1533f414a3d3c02528b774e5cf28e85774b5]) skip testing framework if app created with --skip-test-unit [#5796 Rails 3.0 generator inconsistency state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    https://github.com/rails/rails/commit/bafa1533f414a3d3c02528b774e5c...

    November 11th, 2010 @ 04:36 PM

  17. Aditya Sanghi
    Aditya Sanghi

    José,

    There is another patch here that needs to be applied. As per your suggestion above, I added a patch to set config.generators to false if --skip-activerecord option has been provided.

    Do you want me to create another ticket for it?

    Cheers,
    Aditya

    November 12th, 2010 @ 06:54 AM

  18. José Valim
    José Valim
    • State changed from resolved to open

    There is no need. I am reopening this one, thanks!

    November 12th, 2010 @ 06:56 AM

  19. Aditya Sanghi
    Aditya Sanghi

    ..and bumping this one as well, gently of course.

    December 22nd, 2010 @ 04:58 PM

  20. rails
    rails

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    March 23rd, 2011 @ 12:00 AM

  21. rails
    rails
    • State changed from open to stale

    March 23rd, 2011 @ 12:00 AM