# Plugin tests not running

**URL:** <https://www.ruby-forum.com/t/plugin-tests-not-running/172787>\
**Category:** Rails\
**Created:** [July 28, 2009, 1:35am UTC](https://www.ruby-forum.com/t/plugin-tests-not-running/172787 "2009-07-28T01:35:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cynthia\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/db5fbb/32.png) [@Cynthia\_K](https://www.ruby-forum.com/u/Cynthia_K)\
**Post date:** [July 28, 2009, 1:35am UTC](https://www.ruby-forum.com/t/plugin-tests-not-running/172787/1 "2009-07-28T01:35:43Z")

</div>

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  
plugin,  
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  
can  
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  
from  
Test::Unit::TestCase and using the older “def test\_truth; assert true;  
end”  
syntax. But that didn’t change anything. There are no errors; the tests  
just  
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

# vendor/plugins/my\_plugin/test/my\_plugin\_test.rb

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  
end  
end

# vendor/plugins/my\_plugin/test/test\_helper.rb

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"  
“/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake\_test\_loader.rb”  
“test/my\_plugin\_test.rb”  
vendor/plugins/my\_plugin/test/test\_helper is being read  
In MyPluginTest file

---

<div class="post-metadata">

**Author:** ![Cynthia\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/db5fbb/32.png) [@Cynthia\_K](https://www.ruby-forum.com/u/Cynthia_K)\
**Post date:** [July 28, 2009, 4:40am UTC](https://www.ruby-forum.com/t/plugin-tests-not-running/172787/2 "2009-07-28T04:40:40Z")

</div>

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  
active\_support

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

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/  
environment’)

require ‘test\_help’

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

HTH,  
Nicholas

---

<div class="post-metadata">

**Author:** ![Cynthia\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/db5fbb/32.png) [@Cynthia\_K](https://www.ruby-forum.com/u/Cynthia_K)\
**Post date:** [July 28, 2009, 7:04am UTC](https://www.ruby-forum.com/t/plugin-tests-not-running/172787/3 "2009-07-28T07:04:39Z")

</div>

#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/  
environment.rb’))  
require ‘test\_help’

See [The Basics of Creating Rails Plugins — Ruby on Rails Guides](http://guides.rubyonrails.org/plugins.html#tests) for more  
information.

---

<div class="post-metadata">

**Author:** ![Cynthia\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/db5fbb/32.png) [@Cynthia\_K](https://www.ruby-forum.com/u/Cynthia_K)\
**Post date:** [July 30, 2009, 9:38pm UTC](https://www.ruby-forum.com/t/plugin-tests-not-running/172787/4 "2009-07-30T21:38:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Cynthia\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/db5fbb/32.png) [@Cynthia\_K](https://www.ruby-forum.com/u/Cynthia_K)\
**Post date:** [July 28, 2009, 4:55pm UTC](https://www.ruby-forum.com/t/plugin-tests-not-running/172787/5 "2009-07-28T16:55:50Z")

</div>

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

[https://rails.lighthouseapp.com/projects/8994/tickets/1878](https://rails.lighthouseapp.com/projects/8994/tickets/1878)

–Matt J.
