Skip to content

Blowaway before hooks as well as after hooks to preserve order #2164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/rspec/rails/example/system_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ module SystemExampleGroup
CHARS_TO_TRANSLATE = ['/', '.', ':', ',', "'", '"', " "].freeze

# @private
module BlowAwayAfterTeardownHook
module BlowAwayTeardownHooks
# @private
def before_teardown
end

# @private
def after_teardown
end
Expand Down Expand Up @@ -59,13 +63,18 @@ def app
""".gsub(/\s+/, ' ').strip
end

if ::Rails::VERSION::STRING >= '6.0'
original_before_teardown =
::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:before_teardown)
end

original_after_teardown =
::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:after_teardown)

other.include ActionDispatch::IntegrationTest::Behavior
other.include ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown
other.include ::ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper
other.include BlowAwayAfterTeardownHook
other.include BlowAwayTeardownHooks

attr_reader :driver

Expand Down Expand Up @@ -93,6 +102,9 @@ def driven_by(*args, &blk)
orig_stdout = $stdout
$stdout = StringIO.new
begin
if ::Rails::VERSION::STRING >= '6.0'
original_before_teardown.bind(self).call
end
original_after_teardown.bind(self).call
ensure
myio = $stdout
Expand Down
7 changes: 4 additions & 3 deletions script/downgrade_bundler_on_old_rails
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
set -e
source script/functions.sh

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

gem uninstall -aIx bundler || echo "Warning error occured removing bundler via gem"

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

Expand Down
8 changes: 8 additions & 0 deletions script/predicate_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ function is_mri_2plus {
fi
}

function is_ruby_23 {
if ruby -e "exit(RUBY_VERSION.to_f == 2.3)"; then
return 0
else
return 1
fi
}

function is_ruby_23_plus {
if ruby -e "exit(RUBY_VERSION.to_f >= 2.3)"; then
return 0
Expand Down