Test Injector plugin
Plugin details
Documentation
ruby script/plugin install http://www.infused.org/svn/plugins/test_injector/
A common model might look like:
class User < ActiveRecord::Base has_and_belongs_to_many :groups belongs_to :company has_many :purchases, :class_name => "Order", :dependent => :nullify has_many :subscriptions, :dependent => :destroy has_many :newspapers, :through => subscriptions end
By calling inject_activerecord_tests in the class definition, several test will be injected into the test suite at runtime.
class UserTest < Test::Unit::TestCase fixtures :groups, :companies, :orders, :subscriptions, :newspapers inject_tests :activerecord end
Based on the example User class, the following tests will be run (notice that we didn't have to define any test methods in the test class):
def test_has_and_belongs_to_many_groups # asserts that groups is an Array of Groups end def test_belongs_to_company # asserts that company return an instance of Company end def test_has_many_purchases # asserts that purchases is an Array of Purchases # asserts that associated purchases's user_id column is nullified when the user is deleted end def test_has_many_subscriptions # asserts that subscriptions is an array of Subscriptions # asserts that all subscriptions are destroyed when a User is deleted end def test_has_many_newspapers_through_subscriptions # asserts that newspapers is an array of Newspapers end def test_fixture_defined_for_companies # tests to see if a fixture called 'companies' is defined in the unit test end def test_fixture_defined_for_purchases # tests to see if a fixture called 'orders' is defined in the unit test end def test_fixture_defined_for_subscriptions # tests to see if a fixture called 'subscriptions' is defined in the unit test end def test_fixture_defined_for_newspapers # tests to see if a fixture called 'newspapers' is defined in the unit test end # if the users table has a 'lock_version' column, one test will be defined def test_optimistic_locking # forces a StaleObjectError in order to test that optimisic locking is functioning correctly end # if the users table is using the acts_as_versioned plugin by technoweenie, one test will be defined def test_acts_as_versioned # tests that the versioned table is set up correctly by exercising the versioning system end
You can specify associations that should not be tested when by using the :ignore_associations option:
inject_tests :activerecord, :ignore_associations => [:company, :groups]
As long as you use place the inject_tests declaration at the top of the test class, you can override any of the injected tests by redeclaring a method with the same name. See above for the test method naming.
Further Documentation
There is currently no advanced documentation for this plugin.
New documentationEdit plugin | Back in time (1 older version) | Last edited by: Guest, 7 months ago

