class RSpec::Mocks::ClassNewMethodReference

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. @private

Constants

CLASS_NEW

Public Class Methods

# 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
# File rspec-mocks/lib/rspec/mocks/method_reference.rb, line 198
def self.uses_class_new?(klass)
  ::RSpec::Support.method_handle_for(klass, :new) == CLASS_NEW.bind(klass)
end

Public Instance Methods

# 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