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.

[PATCH] Requiring ActiveSupport::TestCase in a vanilla test fails to run the test case

#2519

It seems that because ActiveSupport::TestCase fails to require test/unit before requiring test/unit/testcase none of the test cases that inherit from ActiveSupport::TestCase are being run.

Normal Rails application tests that require test_helper, which in turn requires environment, don't exhibit this problem. This is possibly due to the fact that test/unit is required somewhere during Rails initialization.

I came across the issue when trying to run tests for a plugin created by Rails' own plugin generator which creates a test_helper which requires ActiveSupport::TestCase

The following won't execute any tests:


  #
  # test_helper.rb
  #
  require 'rubygems'
  require 'active_support'
  require 'active_support/test_case'

  #
  # my_plugin_test.rb
  #
  require 'test_helper'

  class MyPluginTest < ActiveSupport::TestCase
    test "the truth" do
      assert true
    end
  end

I am attaching the one-line patch which fixes it for me. I tried to figure a way to test that the test cases are run, but to be honest, I am lost. If anyone wants to point me to the right direction, I'll give it another try.

Reported by Christos Zisopoulos · April 18th, 2009 @ 07:11 PM

State: new
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. giles bowkett
    giles bowkett

    For what it's worth, you don't need to patch ActiveSupport, you can just require 'test/unit' in your plugin tests.

    Also, I think the best place to patch this is not in ActiveSupport, but the plugin generator.

    August 5th, 2009 @ 12:30 AM

  2. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  3. bingbing