Writing tests for Rails plugins

Posted by Adam on Stack Overflow See other posts from Stack Overflow or by Adam
Published on 2010-03-16T10:56:08Z Indexed on 2010/03/21 11:51 UTC
Read the original article Hit count: 645

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?

© Stack Overflow or respective owner

Related posts about rails

Related posts about ruby-on-rails-plugins