Skip to Content Skip to Search
Methods
A
S
T

Instance Public methods

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.

# 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
# 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
# File activesupport/lib/active_support/testing/setup_and_teardown.rb, line 46
def teardown(*args, &block)
  set_callback(:teardown, :after, *args, &block)
end