Class: RSpec::Mocks::ClassNewMethodReference Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
RSpec::Mocks::ObjectMethodReference
|
Defined in: | rspec-mocks/lib/rspec/mocks/method_reference.rb |
Overview
When a class’s .new
method is stubbed, we want to use the method signature from #initialize
because ‘.new`’s signature is a generic ‘def new(*args)` and it simply delegates to #initialize
and forwards all args…so the method with the actually used signature is #initialize
.
This method reference implementation handles that specific case.
Constant Summary
-
CLASS_NEW =
# File 'rspec-mocks/lib/rspec/mocks/method_reference.rb', line 196::Class.instance_method(:new)
Class Method Summary
- .applies_to?(method_name) ⇒ Boolean Internal use only
-
.uses_class_new?(klass) ⇒ Boolean
Internal use only
Ruby 2’s Method#== is too strict.
ObjectMethodReference
- Inherited
MethodReference
- Inherited
Instance Attribute Summary
MethodReference
- Inherited
#defined? | A method is defined if we are able to get a |
#implemented? | A method is implemented if sending the message does not result in a |
#unimplemented? | Returns true if we definitively know that sending the method will result in a |
Instance Method Summary
Class Method Details
.applies_to?(method_name) ⇒ Boolean
# File 'rspec-mocks/lib/rspec/mocks/method_reference.rb', line 185
def self.applies_to?(method_name) return false unless method_name == :new klass = yield return false unless ::Class === klass && klass.respond_to?(:new, true) # We only want to apply our special logic to normal `new` methods. # Methods that the user has monkeyed with should be left as-is. uses_class_new?(klass) end
.uses_class_new?(klass) ⇒ Boolean
Ruby 2’s Method#== is too strict
# File 'rspec-mocks/lib/rspec/mocks/method_reference.rb', line 202
def self.uses_class_new?(klass) ::RSpec::Support.method_handle_for(klass, :new) == CLASS_NEW.bind(klass) end
Instance Method Details
#with_signature
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/method_reference.rb', line 207
def with_signature @object_reference.when_loaded do |klass| yield Support::MethodSignature.new(klass.instance_method(:initialize)) end end