class Attribute
Represents a predicate that checks if an object has a specific attribute.
Definitions
def initialize(name, predicate)
Initialize a new Attribute predicate.
Signature
-
parameter
nameSymbol, String The attribute name to check for.
-
parameter
predicateObject The predicate to apply to the attribute's value.
Implementation
def initialize(name, predicate)
@name = name
@predicate = predicate
end
def print(output)
Print a representation of this predicate.
Signature
-
parameter
outputOutput The output target.
Implementation
def print(output)
output.write("attribute ", :variable, @name.to_s, :reset, " ", @predicate, :reset)
end
def call(assertions, subject)
Evaluate this predicate against a subject.
Signature
-
parameter
assertionsAssertions The assertions instance to use.
-
parameter
subjectObject The subject to evaluate.
Implementation
def call(assertions, subject)
assertions.nested(self, distinct: true) do |assertions|
assertions.assert(subject.respond_to?(@name), "has attribute")
if @predicate
Expect.new(assertions, subject.public_send(@name)).to(@predicate)
end
end
end