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

Instance Method Details

#argumentObject Also known as: arguments

Convenience method for more fluent specs. Does nothing and returns self.

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.

Overloads:

  • #with(count) ⇒ RespondToMatcher

    Adds a parameter count expectation.

    Parameters:

    • count (Integer, Range, nil)

      (optional) The number of expected parameters.

    Returns:

    • (RespondToMatcher)

      self

  • #with(*keywords) ⇒ Object

    Adds one or more keyword expectations.

    Parameters:

    • keywords (Array<String, Symbol>)

      List of keyword arguments accepted by the method.

    Returns:

    • self

  • #with(count, *keywords) ⇒ Object

    Adds a parameter count expectation and one or more keyword expectations.

    Parameters:

    • count (Integer, Range, nil)

      (optional) The number of expected parameters.

    • keywords (Array<String, Symbol>)

      List of keyword arguments accepted by the method.

    Returns:

    • self



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_blockObject 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.

Returns:

  • self



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_keywordsObject 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.

Parameters:

  • keywords (Array<String, Symbol>)

    List of keyword arguments accepted by the method.

Returns:

  • self



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_argumentsObject 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.

Returns:

  • self



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