Plugin tests not running

I want to build a plugin by extracting some code from an existing app. I
figured the first thing I should do is get comfortable working on a
so I generated a Rails 2.3.3 app, and from inside that, I generated a
plugin. Before doing anything else, I thought I would try to run the
plugin’s generated test. The file loads fine - but the test isn’t run. I
prove that by adding a couple of “puts” statements to the test.

I can’t figure out why the file is found - but the test does not run.
What I
started with is below. Grasping at straws, I also tried current
ActiveSupport out of the picture by having the test inherit directly
Test::Unit::TestCase and using the older “def test_truth; assert true;
syntax. But that didn’t change anything. There are no errors; the tests
get silently ignored. How can this be?

The steps I took:

$ rails generate bar
$ cd bar
$ script/generate plugin MyPlugin
$ cd vendor/plugin/my_plugin
$ rake test

RAILS version 2.3.3
Ruby 1.8.6 on MacOs X


require ‘test_helper’

class MyPluginTest < ActiveSupport::TestCase
puts “In MyPluginTest file”

Replace this with your real tests.

test “the truth” do
puts “In truth test”
assert true


puts “vendor/plugins/my_plugin/test/test_helper is being read”
require ‘rubygems’
require ‘active_support’
require ‘active_support/test_case’

$ rake test
(in /Users/xxx/rails/bar/vendor/plugins/my_plugin)
/usr/local/bin/ruby -I"lib:lib:test"
vendor/plugins/my_plugin/test/test_helper is being read
In MyPluginTest file

Hello Cynthia:

What you did actually makes perfect sense, but after rails got a
wrapper ActiveSupport::TestCase for Test:Unit there seems to be a bit
of a conflict with the testing tasks.

Option 1: If you want to load the Rails environment then just revert
back to RAILS_ROOT and run:

rake test:plugins

for details on this rake task:

rake -D test:plugins

Option 2: If you want to test your plugin in isolation, then you can
modify your plugin test as such:

require ‘test/unit’ # add to test_help, then you could remove the

class FooTest < Test::Unit::TestCase # replacing class FooTest <

Then in your plugin directory rake test should work.

Option 3: I guess you could also load the rails environment in your
test_helper as well

plugin_test_dir = File.dirname(FILE)
require File.join(plugin_test_dir, ‘…/…/…/…/config/

require ‘test_help’

Someone else might want to chime in if I have missed something.


#vendor/plugins/my_plugin/test/test_helper.rb should contain this
ENV[“RAILS_ENV”] = “test”
ENV[‘RAILS_ROOT’] ||= File.dirname(FILE) + ‘/…/…/…/…’
require ‘test/unit’
require File.expand_path(File.join(ENV[‘RAILS_ROOT’], ‘config/
require ‘test_help’

See for more

Thanks. Adding require ‘test/unit’ in my test_helper makes the tests
actually run. OK now to actually add some functionality!

This ticket on Lighthouse seems relevant - you may want to try the
solution there:

–Matt J.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs