Sha256: b512c168e2ba67ce695bb2ec6811910a0a63aad396eae7bb85bbca26a91eb5bf

Contents?: true

Size: 1.21 KB

Versions: 23

Compression:

Stored size: 1.21 KB

Contents

require "active_support/concern"
require "active_support/callbacks"

module ActiveSupport
  module Testing
    # Adds support for +setup+ and +teardown+ callbacks.
    # These callbacks serve as a replacement to overwriting the
    # <tt>#setup</tt> and <tt>#teardown</tt> methods of your TestCase.
    #
    #   class ExampleTest < ActiveSupport::TestCase
    #     setup do
    #       # ...
    #     end
    #
    #     teardown do
    #       # ...
    #     end
    #   end
    module SetupAndTeardown
      extend ActiveSupport::Concern

      included do
        include ActiveSupport::Callbacks
        define_callbacks :setup, :teardown
      end

      module ClassMethods
        # Add a callback, which runs before <tt>TestCase#setup</tt>.
        def setup(*args, &block)
          set_callback(:setup, :before, *args, &block)
        end

        # Add a callback, which runs after <tt>TestCase#teardown</tt>.
        def teardown(*args, &block)
          set_callback(:teardown, :after, *args, &block)
        end
      end

      def before_setup # :nodoc:
        super
        run_callbacks :setup
      end

      def after_teardown # :nodoc:
        run_callbacks :teardown
        super
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 3 rubygems

Version Path
activesupport-5.1.7 lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.7.rc1 lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.6.2 lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.6.1 lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.6 lib/active_support/testing/setup_and_teardown.rb
tdiary-5.0.8 vendor/bundle/gems/activesupport-5.1.5/lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.5 lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.5.rc1 lib/active_support/testing/setup_and_teardown.rb
pract6-0.1.0 .gem/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.4 lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.4.rc1 lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.3 lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.3.rc3 lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.3.rc2 lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.3.rc1 lib/active_support/testing/setup_and_teardown.rb
tdiary-5.0.5 vendor/bundle/gems/activesupport-5.1.2/lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.2 lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.2.rc1 lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.1 lib/active_support/testing/setup_and_teardown.rb
activesupport-5.1.0 lib/active_support/testing/setup_and_teardown.rb