Sha256: 6870e2e15d9ff40ad978aee82d2635e6c573e0fbf3cd98fe119cd57a8c54d758

Contents?: true

Size: 1.33 KB

Versions: 195

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

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
      def self.prepended(klass)
        klass.include ActiveSupport::Callbacks
        klass.define_callbacks :setup, :teardown
        klass.extend ClassMethods
      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:
        begin
          run_callbacks :teardown
        rescue => e
          self.failures << Minitest::UnexpectedError.new(e)
        end

        super
      end
    end
  end
end

Version data entries

195 entries across 180 versions & 23 rubygems

Version Path
activesupport-7.0.8.6 lib/active_support/testing/setup_and_teardown.rb
activesupport-6.1.7.10 lib/active_support/testing/setup_and_teardown.rb
activesupport-6.1.7.9 lib/active_support/testing/setup_and_teardown.rb
activesupport-7.0.8.5 lib/active_support/testing/setup_and_teardown.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.8.4/lib/active_support/testing/setup_and_teardown.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.3.4/lib/active_support/testing/setup_and_teardown.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activesupport-7.0.5.1/lib/active_support/testing/setup_and_teardown.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activesupport-7.0.5.1/lib/active_support/testing/setup_and_teardown.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activesupport-7.0.5.1/lib/active_support/testing/setup_and_teardown.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/testing/setup_and_teardown.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/testing/setup_and_teardown.rb
activesupport-7.1.3.4 lib/active_support/testing/setup_and_teardown.rb
activesupport-7.0.8.4 lib/active_support/testing/setup_and_teardown.rb
activesupport-6.1.7.8 lib/active_support/testing/setup_and_teardown.rb
activesupport-7.1.3.2 lib/active_support/testing/setup_and_teardown.rb
activesupport-7.1.3.1 lib/active_support/testing/setup_and_teardown.rb
activesupport-7.0.8.1 lib/active_support/testing/setup_and_teardown.rb
activesupport-6.1.7.7 lib/active_support/testing/setup_and_teardown.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.3/lib/active_support/testing/setup_and_teardown.rb
activesupport-7.1.3 lib/active_support/testing/setup_and_teardown.rb