class WithOptions
Represents a constraint on method keyword options.
Definitions
def initialize(options)
Initialize a new WithOptions constraint.
Signature
-
parameter
optionsArray(Symbol) The option names that should be present.
Implementation
def initialize(options)
@options = options
end
def print(output)
Print a representation of this constraint.
Signature
-
parameter
outputOutput The output target.
Implementation
def print(output)
output.write("with options ")
output.variable(@options)
end
def call(assertions, subject)
Evaluate this constraint against method parameters.
Signature
-
parameter
assertionsAssertions The assertions instance to use.
-
parameter
subjectArray The method parameters to check.
Implementation
def call(assertions, subject)
options = {}
@options.each{|name| options[name] = nil}
subject.each do |type, name|
options[name] = type
end
assertions.nested(self) do |assertions|
options.each do |name, type|
assertions.assert(type != nil, "option #{name}: is required")
end
end
end