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
Public Class Methods
applies_to?(method_name) { || ... }
click to toggle source
# File 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 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. ::RSpec::Support.method_handle_for(klass, :new).owner == ::Class end
Public Instance Methods
with_signature() { |method_signature(instance_method(:initialize))| ... }
click to toggle source
# File lib/rspec/mocks/method_reference.rb, line 195 def with_signature @object_reference.when_loaded do |klass| yield Support::MethodSignature.new(klass.instance_method(:initialize)) end end