123456789_123456789_123456789_123456789_123456789_

Module: ActiveSupport::Testing::SetupAndTeardown::ClassMethods

Relationships & Source Files
Defined in: activesupport/lib/active_support/testing/setup_and_teardown.rb

Instance Method Summary

Instance Method Details

#around(*args, &block)

Add a callback, which runs between the TestCase#setup callbacks and the TestCase#teardown callbacks. Yields the test class instance and the test case to the block:

class ClientTest < ActiveSupport::TestCase
around do |test_case, block|
  # do client setup
  block.call
  # do client teardown
end
end

Code after a failing test yielded by the block argument will still be executed.

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/setup_and_teardown.rb', line 62

def around(*args, &block)
  set_callback(:test, :around, *args, &block)

  include AroundCallbackSupport unless self < AroundCallbackSupport
end

#setup(*args, &block)

Add a callback, which runs before TestCase#setup.

class ClientTest < ActiveSupport::TestCase
setup do
  # do client setup
end
end
[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/setup_and_teardown.rb', line 35

def setup(*args, &block)
  set_callback(:setup, :before, *args, &block)
end

#teardown(*args, &block)

Add a callback, which runs after TestCase#teardown.

class ClientTest < ActiveSupport::TestCase
teardown do
  # do client teardown
end
end
[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/setup_and_teardown.rb', line 46

def teardown(*args, &block)
  set_callback(:teardown, :after, *args, &block)
end