Class: Sus::Have::Attribute
- Inherits:
-
Object
- Object
- Sus::Have::Attribute
- Defined in:
- lib/sus/have.rb
Overview
Represents a predicate that checks if an object has a specific attribute.
Instance Method Summary collapse
-
#call(assertions, subject) ⇒ Object
Evaluate this predicate against a subject.
-
#initialize(name, predicate) ⇒ Attribute
constructor
Initialize a new Attribute predicate.
-
#print(output) ⇒ Object
Print a representation of this predicate.
Constructor Details
#initialize(name, predicate) ⇒ Attribute
Initialize a new Attribute predicate.
47 48 49 50 |
# File 'lib/sus/have.rb', line 47 def initialize(name, predicate) @name = name @predicate = predicate end |
Instance Method Details
#call(assertions, subject) ⇒ Object
Evaluate this predicate against a subject.
61 62 63 64 65 66 67 68 |
# File 'lib/sus/have.rb', line 61 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 |
#print(output) ⇒ Object
Print a representation of this predicate.
54 55 56 |
# File 'lib/sus/have.rb', line 54 def print(output) output.write("attribute ", :variable, @name.to_s, :reset, " ", @predicate, :reset) end |