123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Matchers::BuiltIn::RespondTo::ArityCheck Private

Relationships & Source Files
Inherits: Object
Defined in: rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(expected_arity, expected_keywords, arbitrary_keywords, unlimited_arguments) ⇒ ArityCheck

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 162

def initialize(expected_arity, expected_keywords, arbitrary_keywords, unlimited_arguments)
  expectation = Support::MethodSignatureExpectation.new

  if expected_arity.is_a?(Range)
    expectation.min_count = expected_arity.min
    expectation.max_count = expected_arity.max
  else
    expectation.min_count = expected_arity
  end

  expectation.keywords = expected_keywords
  expectation.expect_unlimited_arguments = unlimited_arguments
  expectation.expect_arbitrary_keywords  = arbitrary_keywords
  @expectation = expectation
end

Instance Method Details

#matches?(actual, name) ⇒ Boolean

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 178

def matches?(actual, name)
  return true if @expectation.empty?
  verifier_for(actual, name).with_expectation(@expectation).valid?
end

#method_signature_for(actual, name)

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 187

def method_signature_for(actual, name)
  method_handle = Support.method_handle_for(actual, name)

  if name == :new && method_handle.owner === ::Class && ::Class === actual
    Support::MethodSignature.new(actual.instance_method(:initialize))
  else
    Support::MethodSignature.new(method_handle)
  end
end

#verifier_for(actual, name)

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 183

def verifier_for(actual, name)
  Support::StrictSignatureVerifier.new(method_signature_for(actual, name))
end