views:

163

answers:

3

I'm working on a plugin for Rails that would add limited in-memory caching to ActiveRecord's finders. The functionality itself is mature enough, but I can't for the life of me get unit tests to work with the plugin.

I now have under vendor/plugins/my_plugin/test/my_plugin_test.rb a standard subclass of ActiveSupport::TestCase with a couple of basic tests. I try running 'rake test' from the plugin directory, and I have confirmed that this task loads the ruby file with the test case, but it doesn't actually run any of the tests.

I followed the Rails plugin guide (http://guides.rubyonrails.org/plugins.html) where applicable, but it seems to be horribly outdated (it suggests things that Rails now do automatically, etc.)

The only output I get is this:

Kakadu:ingenious_record adam$ rake test
(in /Users/adam/Sites/1_PRK/vendor/plugins/ingenious_record)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -Ilib:lib:test "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" "test/ingenious_record_test.rb" 

The simplest test case looks like this:

require 'test_helper'
require 'active_record'

class IngeniousRecordTest < ActiveSupport::TestCase  
  test "example" do
    assert false
  end
end

This should definitely produce at least some output, and the only test in that file should produce a failed assertion.

Any ideas what I could do to get Rails to run my tests?

+2  A: 

I test my plugins using the Engines plugin's rake tasks:

rake test:plugins:all PLUGIN=myplugin

I'm sure you can do it without Engines, but it is an option. Recent versions of Rails (I'm still on 2.2.2) have Engines support integrated.

Chris
+1  A: 

Apparently there is a little problem with rails 2.2.3, as it does not include the 'test/unit' package/file in plugins. In order to fix your plugin problems, just add the following to the top of your test_helper.rb file:

require 'test/unit'

Found it as a ticket at lighthouse.

Markus Krogh
A: 

very cool. the first post was working for me, didn't try next one

Vel