Sha256: f4706e6aa3212c434737e1262d954bfa1f1262e73b5325bfe7175a3eba544ade
Contents?: true
Size: 1.35 KB
Versions: 2
Compression:
Stored size: 1.35 KB
Contents
# frozen_string_literal: true 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: begin run_callbacks :teardown rescue => e error = e end super ensure raise error if error end end end end
Version data entries
2 entries across 2 versions & 2 rubygems