#To run the tests: rake test #From the plugin's root dir require 'test/unit' #This should be 'test' anyway, but just to make sure RAILS_ENV = "test" #If you need to load your app's environment require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb')) require 'acts_as_monkey' require 'test/mock_model' class Monkey attr_accessor :name, :age, :color def self.validates_presence_of(*a, &b);end def self.before_validation(*a, &b);end def self.before_save(*a, &b);end end class ActsAsMonkeyTest < Test::Unit::TestCase #Standard Test::Unit setup.. def setup #Do stuff before each test end #..and teardown methods def teardown #Do stuff after each test end def test_include Monkey.send(:include, ActsAsMonkey::ActiveRecordExtensions) assert Monkey.methods.include?('acts_as_monkey') Monkey.acts_as_monkey assert Monkey.methods.include?('default_color') assert Monkey.new.methods.include?('smile') end def test_validation monkey = MockModel.new(:name => 'Bobo', :age => 5) assert monkey.valid? monkey = MockModel.new assert !monkey.valid? assert monkey.errors.on('name') end def test_callback monkey = MockModel.new(:name => 'Lucy', :age => 8) assert monkey.valid? assert monkey.color == MockModel.default_color end end