Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Remove some ruby 1.8.6 hacks for eval with args #865

Closed
wants to merge 2 commits into from

2 participants

@soulcutter
Collaborator

I stumbled across some hacks to work around deficiencies in 1.8.6 and started removing them. Interestingly hooks.rb has a call to #instance_eval_with_args that is resisting replacement.

Target for RSpec 3.0

@soulcutter

I thought this line could be a simple replacement, however it breaks several tests.

Collaborator

ah HA. There was a different instance_eval_with_args on Example which is not related to the 1.8.6 hack.

@soulcutter
Collaborator

Note: There's another opportunity for this same cleanup in rspec-expectations

@JonRowe JonRowe commented on the diff
lib/rspec/core/example_group.rb
@@ -164,7 +162,8 @@ def self.find_and_eval_shared(label, name, *args, &customization_block)
raise ArgumentError, "Could not find shared #{label} #{name.inspect}" unless
shared_block = world.shared_example_groups[name]
- module_eval_with_args(*args, &shared_block)
+ module_exec(*args, &shared_block)
+ #module_eval_with_args(*args, &shared_block)
@JonRowe Owner
JonRowe added a note

Any reason why you included a commented out line?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@JonRowe
Owner

I may have neglected to remember this when removing 1.8.6 hacks earlier this week, sorry! I'm closing cause it's already done but if you need to reopen go ahead.

@JonRowe JonRowe closed this
@soulcutter
Collaborator

All good! :+1:

@soulcutter soulcutter deleted the soulcutter:remove-1_8_6-eval-hacks branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  lib/rspec/core.rb
@@ -13,8 +13,6 @@
require_rspec['core/filter_manager']
require_rspec['core/dsl']
require_rspec['core/extensions/kernel']
-require_rspec['core/extensions/instance_eval_with_args']
-require_rspec['core/extensions/module_eval_with_args']
require_rspec['core/extensions/ordered']
require_rspec['core/deprecation']
require_rspec['core/backward_compatibility']
View
2  lib/rspec/core/example.rb
@@ -244,7 +244,7 @@ def instance_eval_with_rescue(context = nil, &block)
# @private
def instance_eval_with_args(*args, &block)
- @example_group_instance.instance_eval_with_args(*args, &block)
+ @example_group_instance.instance_exec(*args, &block)
end
private
View
5 lib/rspec/core/example_group.rb
@@ -14,11 +14,9 @@ module Core
# is declared.
class ExampleGroup
extend MetadataHashBuilder::WithDeprecationWarning
- extend Extensions::ModuleEvalWithArgs
extend Hooks
include MemoizedHelpers
- include Extensions::InstanceEvalWithArgs
include Pending
include SharedExampleGroup
@@ -164,7 +162,8 @@ def self.find_and_eval_shared(label, name, *args, &customization_block)
raise ArgumentError, "Could not find shared #{label} #{name.inspect}" unless
shared_block = world.shared_example_groups[name]
- module_eval_with_args(*args, &shared_block)
+ module_exec(*args, &shared_block)
+ #module_eval_with_args(*args, &shared_block)
@JonRowe Owner
JonRowe added a note

Any reason why you included a commented out line?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
module_eval(&customization_block) if customization_block
end
View
44 lib/rspec/core/extensions/instance_eval_with_args.rb
@@ -1,44 +0,0 @@
-module RSpec
- module Core
- module Extensions
- # @private
- module InstanceEvalWithArgs
- # @private
- #
- # Used internally to support `instance_exec` in Ruby 1.8.6.
- #
- # based on Bounded Spec InstanceExec (Mauricio Fernandez)
- # http://eigenclass.org/hiki/bounded+space+instance_exec
- # - uses singleton_class instead of global InstanceExecHelper module
- # - this keeps it scoped to classes/modules that include this module
- # - only necessary for ruby 1.8.6
- def instance_eval_with_args(*args, &block)
- return instance_exec(*args, &block) if respond_to?(:instance_exec)
-
- # If there are no args and the block doesn't expect any, there's no
- # need to fake instance_exec with our hack below.
- # Notes:
- # * lambda { }.arity # => -1
- # * lambda { || }.arity # => 0
- # * lambda { |*a| }.arity # -1
- return instance_eval(&block) if block.arity < 1 && args.size.zero?
-
- singleton_class = (class << self; self; end)
- begin
- orig_critical, Thread.critical = Thread.critical, true
- n = 0
- n += 1 while respond_to?(method_name="__instance_exec#{n}")
- singleton_class.module_eval{ define_method(method_name, &block) }
- ensure
- Thread.critical = orig_critical
- end
- begin
- return send(method_name, *args)
- ensure
- singleton_class.module_eval{ remove_method(method_name) } rescue nil
- end
- end
- end
- end
- end
-end
View
38 lib/rspec/core/extensions/module_eval_with_args.rb
@@ -1,38 +0,0 @@
-module RSpec
- module Core
- module Extensions
- # @private
- module ModuleEvalWithArgs
- include InstanceEvalWithArgs
-
- # @private
- #
- # Used internally to support `module_exec` in Ruby 1.8.6.
- def module_eval_with_args(*args, &block)
- # ruby > 1.8.6
- return module_exec(*args, &block) if respond_to?(:module_exec)
-
- # If there are no args and the block doesn't expect any, there's no
- # need to fake module_exec with our hack below.
- # Notes:
- # * lambda { }.arity # => -1
- # * lambda { || }.arity # => 0
- # * lambda { |*a| }.arity # => -1
- return module_eval(&block) if block.arity < 1 && args.size.zero?
-
- orig_singleton_methods = singleton_methods
- instance_eval_with_args(*args, &block)
-
- # The only difference between instance_eval and module_eval is static method defs.
- # * `def foo` in instance_eval defines a singleton method on the instance
- # * `def foo` in class/module_eval defines an instance method for the class/module
- # Here we deal with this difference by defining an instance method for
- # each new singleton method.
- # This has the side effect of duplicating methods (all new class methods will
- # become instance methods and vice versa), but I don't see a way around it...
- (singleton_methods - orig_singleton_methods).each { |m| define_method(m, &method(m)) }
- end
- end
- end
- end
-end
Something went wrong with that request. Please try again.