123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Support::MethodSignatureVerifier Private

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
RSpec::Support::LooseSignatureVerifier
Inherits: Object
Defined in: rspec-support/lib/rspec/support/method_signature_verifier.rb

Overview

Abstract base class for signature verifiers.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#arbitrary_kw_args?Boolean (readonly, private)

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/method_signature_verifier.rb', line 357

def arbitrary_kw_args?
  !@arbitrary_kw_args || @signature.arbitrary_kw_args?
end

#kw_args (readonly)

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/method_signature_verifier.rb', line 281

attr_reader :non_kw_args, :kw_args, :min_non_kw_args, :max_non_kw_args

#max_non_kw_args (readonly)

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/method_signature_verifier.rb', line 281

attr_reader :non_kw_args, :kw_args, :min_non_kw_args, :max_non_kw_args

#min_non_kw_args (readonly)

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/method_signature_verifier.rb', line 281

attr_reader :non_kw_args, :kw_args, :min_non_kw_args, :max_non_kw_args

#non_kw_args (readonly)

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/method_signature_verifier.rb', line 281

attr_reader :non_kw_args, :kw_args, :min_non_kw_args, :max_non_kw_args

#unlimited_args?Boolean (readonly, private)

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/method_signature_verifier.rb', line 361

def unlimited_args?
  !@unlimited_args || @signature.unlimited_args?
end

#valid?Boolean (readonly)

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/method_signature_verifier.rb', line 318

def valid?
  missing_kw_args.empty? &&
    invalid_kw_args.empty? &&
    valid_non_kw_args? &&
    arbitrary_kw_args? &&
    unlimited_args?
end

#valid_non_kw_args?Boolean (readonly, private)

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/method_signature_verifier.rb', line 345

def valid_non_kw_args?
  @signature.valid_non_kw_args?(min_non_kw_args, max_non_kw_args)
end

Instance Method Details

#error_message

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/method_signature_verifier.rb', line 326

def error_message
  if missing_kw_args.any?
    "Missing required keyword arguments: %s" % [
      missing_kw_args.join(", ")
    ]
  elsif invalid_kw_args.any?
    "Invalid keyword arguments provided: %s" % [
      invalid_kw_args.join(", ")
    ]
  elsif !valid_non_kw_args?
    "Wrong number of arguments. Expected %s, got %s." % [
      @signature.non_kw_args_arity_description,
      non_kw_args
    ]
  end
end

#invalid_kw_args (private)

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/method_signature_verifier.rb', line 353

def invalid_kw_args
  @signature.invalid_kw_args_from(kw_args)
end

#missing_kw_args (private)

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/method_signature_verifier.rb', line 349

def missing_kw_args
  @signature.missing_kw_args_from(kw_args)
end

#split_args(*args) (private)

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/method_signature_verifier.rb', line 365

def split_args(*args)
  kw_args = if @signature.has_kw_args_in?(args) && !RubyFeatures.kw_arg_separation?
              last = args.pop
              non_kw_args = last.reject { |k, _| k.is_a?(Symbol) }
              if non_kw_args.empty?
                last.keys
              else
                args << non_kw_args
                last.select { |k, _| k.is_a?(Symbol) }.keys
              end
            elsif @signature.has_kw_args_in?(args) && RubyFeatures.kw_arg_separation?
              args.pop.keys
            else
              []
            end

  [args.length, kw_args]
end

#with_expectation(expectation)

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/method_signature_verifier.rb', line 290

def with_expectation(expectation) # rubocop:disable Metrics/MethodLength
  return self unless MethodSignatureExpectation === expectation

  if expectation.empty?
    @min_non_kw_args = @max_non_kw_args = @non_kw_args = nil
    @kw_args     = []
  else
    @min_non_kw_args = @non_kw_args = expectation.min_count || 0
    @max_non_kw_args                = expectation.max_count || @min_non_kw_args

    if RubyFeatures.optional_and_splat_args_supported?
      @unlimited_args = expectation.expect_unlimited_arguments
    else
      @unlimited_args = false
    end

    if RubyFeatures.kw_args_supported?
      @kw_args           = expectation.keywords
      @arbitrary_kw_args = expectation.expect_arbitrary_keywords
    else
      @kw_args           = []
      @arbitrary_kw_args = false
    end
  end

  self
end