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.

Helper test generator

#1199

Currently there's nothing that promotes writing tests for helpers. Neither there is a directory for such tests, nor generators create stubs for them.

The patch adds a helper generator that creates a stub for a helper and a test and modifies other generators that create helpers (controller, resource, scaffold) to generate a test as well. Also modifies the "test" rake task to run helper tests.

The helper test stub looks like this:


require 'test_helper'

class ApplicationHelperTest < ActionView::TestCase
end

And the patch moidifies the test_helper.rb template to include:


class ActionView::TestCase
  # Enable UrlWriter when testing helpers
  include ActionController::UrlWriter

  # Default host for helper tests
  default_url_options[:host] = 'localhost'
end

which allows to use UrlWriter in tests.

The thing I'm not sure about is where to put helper tests. So far they're created in test/helpers which does not really follow the rails conventions cause the directories that exist now (unit, functional) are named by the type of tests, not by objects being tested. Please let me know your thoughts.

Reported by Eugene Bolshakov · October 10th, 2008 @ 07:04 PM

State: resolved
Milestone: 2.x
Assigned to: josh josh
Importance: none

Activity

  1. Dan Croak
    Dan Croak

    +1

    I'm fine with test/helpers or test/unit/helpers.

    October 10th, 2008 @ 07:33 PM

  2. Jack Danger
    Jack Danger

    +1

    test/helpers seems to suggest "helpers for tests" akin to test_helper.rb. I'd recommend test/view_helpers for clarity.

    October 10th, 2008 @ 07:36 PM

  3. Ken Collins
    Ken Collins

    +1 for test/helpers. I think it is important for core to establish the convention while lets vendor test assist code like shoulda to work on top of it.

    October 10th, 2008 @ 07:37 PM

  4. Mike Breen
    Mike Breen

    +1

    test/unit/helpers works for me.

    October 10th, 2008 @ 07:38 PM

  5. Steven Bristol
  6. webmat
    webmat

    +1

    As for where: what about test/unit/helpers? If it's a unit test, it should be somewhere in unit/...

    The 'test/unit/*/_test.rb' glob will support it as it is.

    Plus, some of us already split their test helpers in logical files inside /test/helpers/ :-)

    October 10th, 2008 @ 08:40 PM

  7. josh
    josh
    • Assigned user set to josh
    • State changed from new to open
    • Milestone cleared.

    I've been putting them in test/unit/helpers as well. So lets go with that ;)

    That also means we really don't need a separate rake task. So test:helpers can be merged with test:unit since test:unit should run any nested tests.

    If you can update the patch, I should be able to get it in before the 2.2 beta release.

    October 11th, 2008 @ 07:14 PM

  8. Eugene Bolshakov
    Eugene Bolshakov

    Josh, it makes perfect sense. I've updated the patch so that tests are generated in test/unit/helpers and removed that additional rake task.

    I've also had to slightly tweak railties/test/generators/generator_test_helper.rb to make testing of helper generation possible.

    Also, there seem to be a problem with Rails::Generators::Commands::Create::class_collisions, but I'll inspect it more and will post results in another ticket.

    October 13th, 2008 @ 06:14 PM

  9. Pratik
    Pratik

    I think it's a bit too late for 2.2 :(

    Also, I think the patch should add --no-helper option to generators, which would skip generating helper/helper test. I find myself deleting helper file for most of the controllers I generate. It'd also help to discuss this change on the mailing list.

    October 13th, 2008 @ 06:37 PM

  10. josh
    josh
    • Milestone set to 2.x

    October 14th, 2008 @ 03:04 AM

  11. Repository
    Repository
    • State changed from open to resolved

    (from [3c9beb3dab73013af83b90983f283b76625052b8]) Add helper test generators [#1199 Helper test generator state:resolved]

    Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...

    November 18th, 2008 @ 03:57 AM