Class: Sus::Expect
- Inherits:
-
Object
- Object
- Sus::Expect
- Defined in:
- lib/sus/expect.rb
Instance Attribute Summary collapse
-
#inverted ⇒ Object
readonly
Returns the value of attribute inverted.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #and(predicate) ⇒ Object
-
#initialize(assertions, subject, inverted: false, distinct: false) ⇒ Expect
constructor
A new instance of Expect.
- #not ⇒ Object
- #print(output) ⇒ Object
- #to(predicate) ⇒ Object
Constructor Details
#initialize(assertions, subject, inverted: false, distinct: false) ⇒ Expect
Returns a new instance of Expect.
8 9 10 11 12 13 |
# File 'lib/sus/expect.rb', line 8 def initialize(assertions, subject, inverted: false, distinct: false) @assertions = assertions @subject = subject @inverted = inverted @distinct = true end |
Instance Attribute Details
#inverted ⇒ Object (readonly)
Returns the value of attribute inverted.
16 17 18 |
# File 'lib/sus/expect.rb', line 16 def inverted @inverted end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
15 16 17 |
# File 'lib/sus/expect.rb', line 15 def subject @subject end |
Instance Method Details
#and(predicate) ⇒ Object
45 46 47 |
# File 'lib/sus/expect.rb', line 45 def and(predicate) return to(predicate) end |
#not ⇒ Object
18 19 20 21 22 |
# File 'lib/sus/expect.rb', line 18 def not self.dup.tap do |expect| expect.instance_variable_set(:@inverted, !@inverted) end end |
#print(output) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/sus/expect.rb', line 24 def print(output) output.write("expect ", :variable, @subject.inspect, :reset, " ") if @inverted output.write("to not", :reset) else output.write("to", :reset) end end |
#to(predicate) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sus/expect.rb', line 34 def to(predicate) # This gets the identity scoped to the current call stack, which ensures that any failures are logged at this point in the code. identity = @assertions.identity&.scoped @assertions.nested(self, inverted: @inverted, identity: identity, distinct: @distinct) do |assertions| predicate.call(assertions, @subject) end return self end |