I have a number of models that use STI and I would like to use the same unit test to test each model. For example, I have:
class RegularList < List
class OtherList < List
class ListTest < ActiveSupport::TestCase
fixtures :lists
def test_word_count
list = lists(:regular_list)
assert_equal(0, list.count)
end
end
How would I go about using the test_word_count test for the OtherList model. The test is much longer so I would rather not have to retype it for each model. Thanks.
EDIT: I am trying to use a mixin as per Randy's suggestion. This is what I have but am getting the error: "Object is not missing constant ListTestMethods! (ArgumentError)":
in lib/list_test_methods.rb:
module ListTestMethods
fixtures :lists
def test_word_count
...
end
end
in regular_list_test.rb:
require File.dirname(__FILE__) + '/../test_helper'
class RegularListTest < ActiveSupport::TestCase
include ListTestMethods
protected
def list_type
return :regular_list
end
end
EDIT: Everything seems to work if I put the fixtures call in the RegularListTest and remove it from the module.