Module: RSpec::SleepingKingStudios::Matchers::Shared::MatchParameters
- Included in:
- BuiltIn::RespondToMatcher, Core::ConstructMatcher
- Defined in:
- lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb
Overview
Helper methods for checking the arguments and keywords of a method.
Instance Method Summary collapse
-
#argument ⇒ Object
(also: #arguments)
Convenience method for more fluent specs.
-
#with(*keywords) ⇒ Object
Adds a parameter count expectation and/or one or more keyword expectations.
-
#with_a_block ⇒ Object
(also: #and_a_block)
Adds a block expectation.
-
#with_arbitrary_keywords ⇒ Object
(also: #and_arbitrary_keywords, #with_any_keywords)
Adds an arbitrary keyword expectation, e.g.
-
#with_keywords(*keywords) ⇒ Object
(also: #and_keywords)
Adds one or more keyword expectations.
-
#with_unlimited_arguments ⇒ Object
(also: #and_unlimited_arguments)
Adds an unlimited parameter count expectation, e.g.
Instance Method Details
#argument ⇒ Object Also known as: arguments
Convenience method for more fluent specs. Does nothing and returns self.
13 14 15 |
# File 'lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb', line 13 def argument self end |
#with(count) ⇒ RespondToMatcher #with(*keywords) ⇒ Object #with(count, *keywords) ⇒ Object
Adds a parameter count expectation and/or one or more keyword expectations.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb', line 45 def with *keywords case keywords.first when Range arity = keywords.shift method_signature_expectation.min_arguments = arity.begin method_signature_expectation.max_arguments = arity.end when Integer arity = keywords.shift method_signature_expectation.min_arguments = arity method_signature_expectation.max_arguments = arity end method_signature_expectation.keywords = keywords self end |
#with_a_block ⇒ Object Also known as: and_a_block
Adds a block expectation. The actual object will only match a block expectation if it expects a parameter of the form &block.
68 69 70 71 72 |
# File 'lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb', line 68 def with_a_block method_signature_expectation.block_argument = true self end |
#with_arbitrary_keywords ⇒ Object Also known as: and_arbitrary_keywords, with_any_keywords
Adds an arbitrary keyword expectation, e.g. that the method supports any keywords with splatted hash arguments of the form **kwargs.
77 78 79 80 81 |
# File 'lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb', line 77 def with_arbitrary_keywords method_signature_expectation.any_keywords = true self end |
#with_keywords(*keywords) ⇒ Object Also known as: and_keywords
Adds one or more keyword expectations.
92 93 94 95 96 |
# File 'lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb', line 92 def with_keywords *keywords method_signature_expectation.keywords = keywords self end |
#with_unlimited_arguments ⇒ Object Also known as: and_unlimited_arguments
Adds an unlimited parameter count expectation, e.g. that the method supports splatted array arguments of the form *args.
103 104 105 106 107 |
# File 'lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb', line 103 def with_unlimited_arguments method_signature_expectation.unlimited_arguments = true self end |