class Be
Represents a predicate matcher that can be used with expect(...).to be(...).
Nested
Definitions
def initialize(*arguments)
Initialize a new Be predicate.
Signature
-
parameter
argumentsArray The method name and arguments to call on the subject.
Implementation
def initialize(*arguments)
@arguments = arguments
end
def |(other)
Combine this predicate with another using OR logic.
Signature
-
parameter
otherObject Another predicate to combine.
-
returns
Or A new OR predicate.
Implementation
def |(other)
Or.new([self, other])
end
def or(*others)
Combine this predicate with others using OR logic.
Signature
-
parameter
othersArray Other predicates to combine.
-
returns
Or A new OR predicate.
Implementation
def or(*others)
Or.new([self, *others])
end
def &(other)
Combine this predicate with another using AND logic.
Signature
-
parameter
otherObject Another predicate to combine.
-
returns
And A new AND predicate.
Implementation
def &(other)
And.new([self, other])
end
def and(*others)
Combine this predicate with others using AND logic.
Signature
-
parameter
othersArray Other predicates to combine.
-
returns
And A new AND predicate.
Implementation
def and(*others)
And.new([self, *others])
end
def print(output)
Print a representation of this predicate.
Signature
-
parameter
outputOutput The output target.
Implementation
def print(output)
operation, *arguments = *@arguments
output.write("be ", :be, operation.to_s, :reset)
if arguments.any?
output.write(" ")
arguments.each do |argument|
output.variable(argument)
end
end
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) do |assertions|
assertions.assert(subject.public_send(*@arguments))
end
end
NIL = Be.new(:nil?)
A predicate that checks if the subject is nil.