Class: Sus::Have::Attribute
- Inherits:
-
Object
- Object
- Sus::Have::Attribute
- Defined in:
- lib/sus/have.rb
Instance Method Summary collapse
- #call(assertions, subject) ⇒ Object
-
#initialize(name, predicate) ⇒ Attribute
constructor
A new instance of Attribute.
- #print(output) ⇒ Object
Constructor Details
#initialize(name, predicate) ⇒ Attribute
Returns a new instance of Attribute.
33 34 35 36 |
# File 'lib/sus/have.rb', line 33 def initialize(name, predicate) @name = name @predicate = predicate end |
Instance Method Details
#call(assertions, subject) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/sus/have.rb', line 42 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
38 39 40 |
# File 'lib/sus/have.rb', line 38 def print(output) output.write("attribute ", :variable, @name.to_s, :reset, " ", @predicate, :reset) end |