Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Use `method_handle_for` from rspec-support. #403

Merged
merged 1 commit into from

1 participant

@myronmarston
Owner

No description provided.

@myronmarston myronmarston merged commit bc292d8 into master
@myronmarston myronmarston deleted the use-method-handle-for-from-support branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 1, 2014
  1. @myronmarston
This page is out of date. Refresh to see the latest.
View
26 lib/rspec/expectations.rb
@@ -57,31 +57,5 @@ module Expectations
else
Class.new(::StandardError)
end
-
- # @api private
- KERNEL_METHOD_METHOD = ::Kernel.instance_method(:method)
-
- # @api private
- #
- # Used internally to get a method handle for a particular object
- # and method name.
- #
- # Includes handling for a few special cases:
- #
- # - Objects that redefine #method (e.g. an HTTPRequest struct)
- # - BasicObject subclasses that mixin a Kernel dup (e.g. SimpleDelegator)
- if RUBY_VERSION.to_i >= 2
- def self.method_handle_for(object, method_name)
- KERNEL_METHOD_METHOD.bind(object).call(method_name)
- end
- else
- def self.method_handle_for(object, method_name)
- if ::Kernel === object
- KERNEL_METHOD_METHOD.bind(object).call(method_name)
- else
- object.method(method_name)
- end
- end
- end
end
end
View
4 lib/rspec/matchers/built_in/operators.rb
@@ -1,3 +1,5 @@
+require 'rspec/support'
+
module RSpec
module Matchers
module BuiltIn
@@ -66,7 +68,7 @@ def description
private
def uses_generic_implementation_of?(op)
- Expectations.method_handle_for(@actual, op).owner == ::Kernel
+ Support.method_handle_for(@actual, op).owner == ::Kernel
rescue NameError
false
end
View
52 spec/rspec/expectations_spec.rb
@@ -1,52 +0,0 @@
-module RSpec
- describe Expectations do
- describe '.method_handle_for(object, method_name)' do
-
- class UntamperedClass
- def foo
- :bar
- end
- end
-
- class ClassWithMethodOverridden < UntamperedClass
- def method
- :baz
- end
- end
-
- if RUBY_VERSION.to_f > 1.8
- class BasicClass < BasicObject
- def foo
- :bar
- end
- end
-
- class BasicClassWithKernel < BasicClass
- include ::Kernel
- end
- end
-
- it 'fetches method definitions for vanilla objects' do
- object = UntamperedClass.new
- expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
- end
-
- it 'fetches method definitions for objects with method redefined' do
- object = ClassWithMethodOverridden.new
- expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
- end
-
- it 'fetches method definitions for basic objects', :if => RUBY_VERSION.to_i >= 2 do
- pending "RBX doesn't yet support this", :if => RUBY_ENGINE == 'rbx' do
- object = BasicClass.new
- expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
- end
- end
-
- it 'fetches method definitions for basic objects with kernel mixed in', :if => RUBY_VERSION.to_f > 1.8 do
- object = BasicClassWithKernel.new
- expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
- end
- end
- end
-end
Something went wrong with that request. Please try again.