Module: ActiveSupport::Testing::SetupAndTeardown

Defined in:
lib/active_support/testing/setup_and_teardown.rb

Overview

Adds support for setup and teardown callbacks. These callbacks serve as a replacement to overwriting the #setup and #teardown methods of your TestCase.

class ExampleTest < ActiveSupport::TestCase
  setup do
    # ...
  end

  teardown do
    # ...
  end
end

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(klass) ⇒ Object


21
22
23
24
25
# File 'lib/active_support/testing/setup_and_teardown.rb', line 21

def self.prepended(klass)
  klass.include ActiveSupport::Callbacks
  klass.define_callbacks :setup, :teardown
  klass.extend ClassMethods
end

Instance Method Details

#after_teardownObject

:nodoc:


44
45
46
47
48
49
50
51
52
# File 'lib/active_support/testing/setup_and_teardown.rb', line 44

def after_teardown # :nodoc:
  begin
    run_callbacks :teardown
  rescue => e
    self.failures << Minitest::UnexpectedError.new(e)
  end

  super
end

#before_setupObject

:nodoc:


39
40
41
42
# File 'lib/active_support/testing/setup_and_teardown.rb', line 39

def before_setup # :nodoc:
  super
  run_callbacks :setup
end