Class: RSpec::Support::MethodSignatureVerifier Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/support/method_signature_verifier.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Abstract base class for signature verifiers.

Direct Known Subclasses

LooseSignatureVerifier

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(signature, args = []) ⇒ MethodSignatureVerifier

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MethodSignatureVerifier.



242
243
244
245
246
247
# File 'lib/rspec/support/method_signature_verifier.rb', line 242

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

Instance Attribute Details

#kw_argsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



240
241
242
# File 'lib/rspec/support/method_signature_verifier.rb', line 240

def kw_args
  @kw_args
end

#max_non_kw_argsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



240
241
242
# File 'lib/rspec/support/method_signature_verifier.rb', line 240

def max_non_kw_args
  @max_non_kw_args
end

#min_non_kw_argsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



240
241
242
# File 'lib/rspec/support/method_signature_verifier.rb', line 240

def min_non_kw_args
  @min_non_kw_args
end

#non_kw_argsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



240
241
242
# File 'lib/rspec/support/method_signature_verifier.rb', line 240

def non_kw_args
  @non_kw_args
end

Instance Method Details

#error_messageObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/rspec/support/method_signature_verifier.rb', line 285

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?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


277
278
279
280
281
282
283
# File 'lib/rspec/support/method_signature_verifier.rb', line 277

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

#with_expectation(expectation) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable MethodLength



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/rspec/support/method_signature_verifier.rb', line 249

def with_expectation(expectation) # rubocop:disable 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