Add extension to Test::Unit and ActiveSupport::TestCase
#before_test : do something before lauching a test. As with Rspec
#should_have_callbacks : shoulda doesn’t have macro to test presence of callbacks, here is one.
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
If your model has callback :my_callback on before_create, just check it in your test by :
class .... < ActiveSupport::TestCase should_have_callbacks :before_create, :my_callback end
You can also pass an array :
should_have_callbacks :before_create, [:my_callback_1, :my_callback_2]
gem install test_unit_extend
If you use ActiveSupport::TestCase, it doesn’t work with ActiveSupport 3 (In Development)