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

Ruby 2.5 fixes #2497

Merged
merged 3 commits into from Jan 2, 2018
Jump to file or symbol
Failed to load files and symbols.
+30 −0
Diff settings

Always

Just for now

Viewing a subset of changes. View all
Prev

Work around regressions introduced by lazy proc allocation.

This Ruby 2.5 feature is causing bugs with our hooks because
we depend upon `Hook#==` working properly for the same source
hook block. In Ruby 2.5 they introduced lazy proc allocation
which can result in two `Hook` instances which were previously
correctly considered to be equal to no longer be considered
equal. To work around this, we just need to invoke a method on
the proc before passing it along to other methods.

Note that there might be other bugs introduced by the Ruby 2.5
change, but this fixes the only test failures due to it, so this
is all we are changing for now.

Fixes #2488.
  • Loading branch information...
myronmarston committed Jan 1, 2018
commit 84670489bb4943a62e783bd65f96e4b55360b141
@@ -1808,6 +1808,12 @@ def before(scope=nil, *meta, &block)
handle_suite_hook(scope, meta) do
@before_suite_hooks << Hooks::BeforeHook.new(block, {})
end || begin
# defeat Ruby 2.5 lazy proc allocation to ensure
# the methods below are passed the same proc instances
# so `Hook` equality is preserved. For more info, see:
# https://bugs.ruby-lang.org/issues/14045#note-5
block.__id__
add_hook_to_existing_matching_groups(meta, scope) { |g| g.before(scope, *meta, &block) }
super(scope, *meta, &block)
end
@@ -1831,6 +1837,12 @@ def prepend_before(scope=nil, *meta, &block)
handle_suite_hook(scope, meta) do
@before_suite_hooks.unshift Hooks::BeforeHook.new(block, {})
end || begin
# defeat Ruby 2.5 lazy proc allocation to ensure
# the methods below are passed the same proc instances
# so `Hook` equality is preserved. For more info, see:
# https://bugs.ruby-lang.org/issues/14045#note-5
block.__id__
add_hook_to_existing_matching_groups(meta, scope) { |g| g.prepend_before(scope, *meta, &block) }
super(scope, *meta, &block)
end
@@ -1849,6 +1861,12 @@ def after(scope=nil, *meta, &block)
handle_suite_hook(scope, meta) do
@after_suite_hooks.unshift Hooks::AfterHook.new(block, {})
end || begin
# defeat Ruby 2.5 lazy proc allocation to ensure
# the methods below are passed the same proc instances
# so `Hook` equality is preserved. For more info, see:
# https://bugs.ruby-lang.org/issues/14045#note-5
block.__id__
add_hook_to_existing_matching_groups(meta, scope) { |g| g.after(scope, *meta, &block) }
super(scope, *meta, &block)
end
@@ -1872,6 +1890,12 @@ def append_after(scope=nil, *meta, &block)
handle_suite_hook(scope, meta) do
@after_suite_hooks << Hooks::AfterHook.new(block, {})
end || begin
# defeat Ruby 2.5 lazy proc allocation to ensure
# the methods below are passed the same proc instances
# so `Hook` equality is preserved. For more info, see:
# https://bugs.ruby-lang.org/issues/14045#note-5
block.__id__
add_hook_to_existing_matching_groups(meta, scope) { |g| g.append_after(scope, *meta, &block) }
super(scope, *meta, &block)
end
@@ -1881,6 +1905,12 @@ def append_after(scope=nil, *meta, &block)
#
# See {Hooks#around} for full `around` hook docs.
def around(scope=nil, *meta, &block)
# defeat Ruby 2.5 lazy proc allocation to ensure
# the methods below are passed the same proc instances
# so `Hook` equality is preserved. For more info, see:
# https://bugs.ruby-lang.org/issues/14045#note-5
block.__id__
add_hook_to_existing_matching_groups(meta, scope) { |g| g.around(scope, *meta, &block) }
super(scope, *meta, &block)
end
ProTip! Use n and p to navigate between commits in a pull request.