1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #32733 from Edouard-chin/ec-setupand-teardown

`SetupAndTeardown` has few caveats that breaks libraries
This commit is contained in:
Rafael França 2018-04-27 16:20:16 -04:00 committed by GitHub
commit bb2a3afafb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 13 deletions

View file

@ -130,7 +130,7 @@ module ActiveSupport
alias_method :method_name, :name
include ActiveSupport::Testing::TaggedLogging
include ActiveSupport::Testing::SetupAndTeardown
prepend ActiveSupport::Testing::SetupAndTeardown
include ActiveSupport::Testing::Assertions
include ActiveSupport::Testing::Deprecation
include ActiveSupport::Testing::TimeHelpers

View file

@ -1,6 +1,5 @@
# frozen_string_literal: true
require "active_support/concern"
require "active_support/callbacks"
module ActiveSupport
@ -19,11 +18,10 @@ module ActiveSupport
# end
# end
module SetupAndTeardown
extend ActiveSupport::Concern
included do
include ActiveSupport::Callbacks
define_callbacks :setup, :teardown
def self.prepended(klass)
klass.include ActiveSupport::Callbacks
klass.define_callbacks :setup, :teardown
klass.extend ClassMethods
end
module ClassMethods
@ -47,12 +45,10 @@ module ActiveSupport
begin
run_callbacks :teardown
rescue => e
error = e
self.failures << Minitest::UnexpectedError.new(e)
end
super
ensure
raise error if error
end
end
end

View file

@ -4,13 +4,14 @@ require "abstract_unit"
module OtherAfterTeardown
def after_teardown
super
@witness = true
end
end
class AfterTeardownTest < Minitest::Test
class AfterTeardownTest < ActiveSupport::TestCase
include OtherAfterTeardown
include ActiveSupport::Testing::SetupAndTeardown
attr_writer :witness
@ -21,11 +22,12 @@ class AfterTeardownTest < Minitest::Test
end
def after_teardown
assert_raises MyError do
assert_changes -> { failures.count }, from: 0, to: 1 do
super
end
assert_equal true, @witness
failures.clear
end
def test_teardown_raise_but_all_after_teardown_method_are_called