This project is archived and is in readonly mode.

#1199 ✓resolved
Eugene Bolshakov

Helper test generator

Reported by Eugene Bolshakov | October 10th, 2008 @ 07:04 PM | in 2.x

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

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'

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.

Comments and changes to this ticket

  • Dan Croak

    Dan Croak October 10th, 2008 @ 07:33 PM


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

  • Jack Danger

    Jack Danger October 10th, 2008 @ 07:36 PM


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

  • Ken Collins

    Ken Collins October 10th, 2008 @ 07:37 PM

    +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.

  • Mike Breen

    Mike Breen October 10th, 2008 @ 07:38 PM


    test/unit/helpers works for me.

  • Steven Bristol
  • webmat

    webmat October 10th, 2008 @ 08:40 PM


    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/ :-)

  • josh

    josh October 11th, 2008 @ 07:14 PM

    • 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.

  • Eugene Bolshakov

    Eugene Bolshakov October 13th, 2008 @ 06:14 PM

    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.

  • Pratik

    Pratik October 13th, 2008 @ 06:37 PM

    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.

  • josh

    josh October 14th, 2008 @ 03:04 AM

    • Milestone set to 2.x
  • Repository

    Repository November 18th, 2008 @ 03:57 AM

    • State changed from “open” to “resolved”

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

    Signed-off-by: Joshua Peek

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>


Referenced by