class RSpec::Support::StrictSignatureVerifier
Abstract base class for signature verifiers.
@api private
Attributes
kw_args[R]
max_non_kw_args[R]
min_non_kw_args[R]
non_kw_args[R]
Public Class Methods
new(signature, args=[])
click to toggle source
# File lib/rspec/support/method_signature_verifier.rb, line 281 def initialize(signature, args=[]) @signature = signature @non_kw_args, @kw_args = split_args(*args) @min_non_kw_args = @max_non_kw_args = @non_kw_args @arbitrary_kw_args = @unlimited_args = false end
Public Instance Methods
error_message()
click to toggle source
# File lib/rspec/support/method_signature_verifier.rb, line 324 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
valid?()
click to toggle source
# File lib/rspec/support/method_signature_verifier.rb, line 316 def valid? missing_kw_args.empty? && invalid_kw_args.empty? && valid_non_kw_args? && arbitrary_kw_args? && unlimited_args? end
with_expectation(expectation)
click to toggle source
# File lib/rspec/support/method_signature_verifier.rb, line 288 def with_expectation(expectation) # rubocop:disable MethodLength, Metrics/PerceivedComplexity 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
Private Instance Methods
arbitrary_kw_args?()
click to toggle source
# File lib/rspec/support/method_signature_verifier.rb, line 355 def arbitrary_kw_args? !@arbitrary_kw_args || @signature.arbitrary_kw_args? end
invalid_kw_args()
click to toggle source
# File lib/rspec/support/method_signature_verifier.rb, line 351 def invalid_kw_args @signature.invalid_kw_args_from(kw_args) end
missing_kw_args()
click to toggle source
# File lib/rspec/support/method_signature_verifier.rb, line 347 def missing_kw_args @signature.missing_kw_args_from(kw_args) end
split_args(*args)
click to toggle source
# File lib/rspec/support/method_signature_verifier.rb, line 363 def split_args(*args) kw_args = if @signature.has_kw_args_in?(args) 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 else [] end [args.length, kw_args] end
unlimited_args?()
click to toggle source
# File lib/rspec/support/method_signature_verifier.rb, line 359 def unlimited_args? !@unlimited_args || @signature.unlimited_args? end
valid_non_kw_args?()
click to toggle source
# File lib/rspec/support/method_signature_verifier.rb, line 343 def valid_non_kw_args? @signature.valid_non_kw_args?(min_non_kw_args, max_non_kw_args) end