Class: Sus::RespondTo::WithParameters
- Inherits:
-
Object
- Object
- Sus::RespondTo::WithParameters
- Defined in:
- lib/sus/respond_to.rb
Overview
Represents a constraint on method parameters.
Instance Method Summary collapse
-
#call(assertions, subject) ⇒ Object
Evaluate this constraint against method parameters.
-
#initialize(parameters) ⇒ WithParameters
constructor
Initialize a new WithParameters constraint.
Constructor Details
#initialize(parameters) ⇒ WithParameters
Initialize a new WithParameters constraint.
13 14 15 |
# File 'lib/sus/respond_to.rb', line 13 def initialize(parameters) @parameters = parameters end |
Instance Method Details
#call(assertions, subject) ⇒ Object
Evaluate this constraint against method parameters.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sus/respond_to.rb', line 20 def call(assertions, subject) parameters = @parameters.dup assertions.nested(self) do |assertions| expected_name = parameters.shift subject.each do |type, name| case type when :req assertions.assert(name == expected_name, "parameter #{expected_name} is required, but was #{name}") when :opt break if expected_name.nil? assertions.assert(name == expected_name, "parameter #{expected_name} is specified, but was #{name}") else break end end end end |