Class: Sus::Have::Key
- Inherits:
-
Object
- Object
- Sus::Have::Key
- Defined in:
- lib/sus/have.rb
Instance Method Summary collapse
- #call(assertions, subject) ⇒ Object
-
#initialize(name, predicate = nil) ⇒ Key
constructor
A new instance of Key.
- #print(output) ⇒ Object
Constructor Details
#initialize(name, predicate = nil) ⇒ Key
Returns a new instance of Key.
12 13 14 15 |
# File 'lib/sus/have.rb', line 12 def initialize(name, predicate = nil) @name = name @predicate = predicate end |
Instance Method Details
#call(assertions, subject) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/sus/have.rb', line 21 def call(assertions, subject) # We want to group all the assertions in to a distinct group: assertions.nested(self, distinct: true) do |assertions| assertions.assert(subject.key?(@name), "has key") if @predicate Expect.new(assertions, subject[@name]).to(@predicate) end end end |
#print(output) ⇒ Object
17 18 19 |
# File 'lib/sus/have.rb', line 17 def print(output) output.write("key ", :variable, @name.inspect, :reset, " ", @predicate, :reset) end |