Class: RSpec::Support::MethodSignatureVerifier Private
- Inherits:
-
Object
- Object
- RSpec::Support::MethodSignatureVerifier
- 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
Instance Attribute Summary collapse
- #kw_args ⇒ Object readonly private
- #max_non_kw_args ⇒ Object readonly private
- #min_non_kw_args ⇒ Object readonly private
- #non_kw_args ⇒ Object readonly private
Instance Method Summary collapse
- #error_message ⇒ Object private
-
#initialize(signature, args = []) ⇒ MethodSignatureVerifier
constructor
private
A new instance of MethodSignatureVerifier.
- #valid? ⇒ Boolean private
-
#with_expectation(expectation) ⇒ Object
private
rubocop:disable Metrics/MethodLength.
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.
308 309 310 311 312 313 |
# File 'lib/rspec/support/method_signature_verifier.rb', line 308 def initialize(signature, args=[]) @signature = signature @non_kw_args, @kw_args = split_args(args.clone) @min_non_kw_args = @max_non_kw_args = @non_kw_args @arbitrary_kw_args = @unlimited_args = false end |
Instance Attribute Details
#kw_args ⇒ Object (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.
306 307 308 |
# File 'lib/rspec/support/method_signature_verifier.rb', line 306 def kw_args @kw_args end |
#max_non_kw_args ⇒ Object (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.
306 307 308 |
# File 'lib/rspec/support/method_signature_verifier.rb', line 306 def max_non_kw_args @max_non_kw_args end |
#min_non_kw_args ⇒ Object (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.
306 307 308 |
# File 'lib/rspec/support/method_signature_verifier.rb', line 306 def min_non_kw_args @min_non_kw_args end |
#non_kw_args ⇒ Object (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.
306 307 308 |
# File 'lib/rspec/support/method_signature_verifier.rb', line 306 def non_kw_args @non_kw_args end |
Instance Method Details
#error_message ⇒ 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.
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/rspec/support/method_signature_verifier.rb', line 351 def 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.
343 344 345 346 347 348 349 |
# File 'lib/rspec/support/method_signature_verifier.rb', line 343 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 Metrics/MethodLength
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/rspec/support/method_signature_verifier.rb', line 315 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 |