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

Instance Method Details

#argumentObject Also known as: arguments

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

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.

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



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_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



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



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.

Parameters:

  • keywords (Array<String, Symbol>)

    List of keyword arguments accepted by the method.

Returns:

  • self



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_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



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