From 3f7081bc4817f3cd360cb144a5b4663d29f7bc12 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Fri, 13 Sep 2024 19:51:58 +0200 Subject: [PATCH] Drop `Proc#bind` Proc responds to `instance_exec` since forever ago Official Ruby docs only go back to 2.0, so I added that as the minimum version, if someone should for some reason still use rubies before that. https://docs.ruby-lang.org/en/2.0.0/BasicObject.html#method-i-instance_exec --- lib/shoulda/context.rb | 1 - lib/shoulda/context/context.rb | 21 +++------------------ lib/shoulda/context/proc_extensions.rb | 14 -------------- 3 files changed, 3 insertions(+), 33 deletions(-) delete mode 100644 lib/shoulda/context/proc_extensions.rb diff --git a/lib/shoulda/context.rb b/lib/shoulda/context.rb index d3ad1079..03fbd671 100644 --- a/lib/shoulda/context.rb +++ b/lib/shoulda/context.rb @@ -2,7 +2,6 @@ require "shoulda/context/configuration" require "shoulda/context/context" require "shoulda/context/dsl" -require "shoulda/context/proc_extensions" require "shoulda/context/test_framework_detection" require "shoulda/context/version" require "shoulda/context/world" diff --git a/lib/shoulda/context/context.rb b/lib/shoulda/context/context.rb index f5e1888e..120cd65d 100644 --- a/lib/shoulda/context/context.rb +++ b/lib/shoulda/context/context.rb @@ -36,12 +36,7 @@ def initialize(name, parent, &blk) end def merge_block(&blk) - if self.respond_to?(:instance_exec) - self.instance_exec(&blk) - else - # deprecated in Rails 4.x - blk.bind(self).call - end + self.instance_exec(&blk) end def context(name, &blk) @@ -170,23 +165,13 @@ def run_parent_setup_blocks(binding) def run_current_setup_blocks(binding) setup_blocks.each do |setup_block| - if binding.respond_to?(:instance_exec) - binding.instance_exec(&setup_block) - else - # deprecated in Rails 4.x - setup_block.bind(binding).call - end + binding.instance_exec(&setup_block) end end def run_all_teardown_blocks(binding) teardown_blocks.reverse.each do |teardown_block| - if binding.respond_to?(:instance_exec) - binding.instance_exec(&teardown_block) - else - # deprecated in Rails 4.x - teardown_block.bind(binding).call - end + binding.instance_exec(&teardown_block) end self.parent.run_all_teardown_blocks(binding) if am_subcontext? end diff --git a/lib/shoulda/context/proc_extensions.rb b/lib/shoulda/context/proc_extensions.rb deleted file mode 100644 index 0d577df9..00000000 --- a/lib/shoulda/context/proc_extensions.rb +++ /dev/null @@ -1,14 +0,0 @@ -# Stolen straight from ActiveSupport - -class Proc #:nodoc: - def bind(object) - block, time = self, Time.now - (class << object; self end).class_eval do - method_name = "__bind_#{time.to_i}_#{time.usec}" - define_method(method_name, &block) - method = instance_method(method_name) - remove_method(method_name) - method - end.bind(object) - end -end