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 parameters and keywords (Ruby 2.0 only) 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.
14 15 16 |
# File 'lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb', line 14 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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb', line 46 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 # case 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.
69 70 71 72 73 |
# File 'lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb', line 69 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.
78 79 80 81 82 |
# File 'lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb', line 78 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.
93 94 95 96 97 |
# File 'lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb', line 93 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.
104 105 106 107 108 |
# File 'lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb', line 104 def with_unlimited_arguments method_signature_expectation.unlimited_arguments = true self end |