Overview
Add extension to Test::Unit.
#before_test : do something before lauch a test #should_have_callbacks : shoulda doesn’t have macro to test presence of callbacks, here is one.
before_test
class .… < Test::Unit::TestCase
before_test :test_me, :setup_for_test_me
def test_me
assert_equal "Cup of tea please", @var # OK
end
private
def setup_for_test_me
@var = "Cup of tea please"
end
end
should_have_callbacks
If your model has callback :my_callback on before_create, just check it in your test by :
should_have_callbacks :before_create, :my_callback
You can also pass an array :
should_have_callbacks :before_create, [:my_callback_1, :my_callback_2]
Install
gem install test_unit_extend
Dependencies
before_test : if you use ActiveSupport::TestCase, it doesn’t work with ActiveSupport 3 (In Development)