Skip to content

Commit b118fc6

Browse files
authored
Merge pull request #2164 from rspec/fix-teardown-hooks
Blowaway before hooks as well as after hooks to preserve order
2 parents 9c6d8f3 + 395f34b commit b118fc6

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

lib/rspec/rails/example/system_example_group.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ module SystemExampleGroup
1515
CHARS_TO_TRANSLATE = ['/', '.', ':', ',', "'", '"', " "].freeze
1616

1717
# @private
18-
module BlowAwayAfterTeardownHook
18+
module BlowAwayTeardownHooks
19+
# @private
20+
def before_teardown
21+
end
22+
1923
# @private
2024
def after_teardown
2125
end
@@ -59,13 +63,18 @@ def app
5963
""".gsub(/\s+/, ' ').strip
6064
end
6165

66+
if ::Rails::VERSION::STRING >= '6.0'
67+
original_before_teardown =
68+
::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:before_teardown)
69+
end
70+
6271
original_after_teardown =
6372
::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:after_teardown)
6473

6574
other.include ActionDispatch::IntegrationTest::Behavior
6675
other.include ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown
6776
other.include ::ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper
68-
other.include BlowAwayAfterTeardownHook
77+
other.include BlowAwayTeardownHooks
6978

7079
attr_reader :driver
7180

@@ -93,6 +102,9 @@ def driven_by(*args, &blk)
93102
orig_stdout = $stdout
94103
$stdout = StringIO.new
95104
begin
105+
if ::Rails::VERSION::STRING >= '6.0'
106+
original_before_teardown.bind(self).call
107+
end
96108
original_after_teardown.bind(self).call
97109
ensure
98110
myio = $stdout

script/downgrade_bundler_on_old_rails

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
set -e
66
source script/functions.sh
77

8-
if ruby -e "exit(ENV['RAILS_VERSION'].to_f < 5)"; then
8+
if ruby -e "exit(ENV['RAILS_VERSION'].scan(/\d+\.\d+.\d+/)[0].to_f < 5)"; then
99
# On Rails versions less than 5, Bundler 2.0 is not supported
1010
echo "Warning dowgrading to older version of Bundler"
11-
gem uninstall -aIx bundler
11+
12+
gem uninstall -aIx bundler || echo "Warning error occured removing bundler via gem"
1213

1314
# this only works on Ruby 2.3 which is luckily the version we need to fix
14-
if is_ruby_23_plus; then
15+
if is_ruby_23; then
1516
rvm @global do gem uninstall -aIx bundler
1617
fi
1718

script/predicate_functions.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ function is_mri_2plus {
5757
fi
5858
}
5959

60+
function is_ruby_23 {
61+
if ruby -e "exit(RUBY_VERSION.to_f == 2.3)"; then
62+
return 0
63+
else
64+
return 1
65+
fi
66+
}
67+
6068
function is_ruby_23_plus {
6169
if ruby -e "exit(RUBY_VERSION.to_f >= 2.3)"; then
6270
return 0

0 commit comments

Comments
 (0)