Module: Tst::Assertions
- Included in:
- Runner
- Defined in:
- lib/tst.rb
Overview
Assertions available in ‘tst` blocks.
Instance Method Summary collapse
-
#assert(value) ⇒ Object
Fails if ‘value` is `false` or `nil`.
-
#assert_equal(expected, actual) ⇒ Object
Fails unless it’s arguments are equal (with ‘==`).
-
#assert_raises(expected = StandardError) ⇒ Object
Succeeds if it catches an error AND that error is a ‘kind_of?` the `expected` error.
Instance Method Details
#assert(value) ⇒ Object
Fails if ‘value` is `false` or `nil`. Succeeds otherwise.
22 23 24 25 |
# File 'lib/tst.rb', line 22 def assert(value) return if value raise Failure.new("Failure: Truthiness", "not false or nil", value) end |
#assert_equal(expected, actual) ⇒ Object
Fails unless it’s arguments are equal (with ‘==`).
28 29 30 31 |
# File 'lib/tst.rb', line 28 def assert_equal(expected, actual) return if expected == actual raise Failure.new("Equality Failure", expected, actual) end |
#assert_raises(expected = StandardError) ⇒ Object
Succeeds if it catches an error AND that error is a ‘kind_of?` the `expected` error. Fails otherwise.
35 36 37 38 39 40 41 42 43 |
# File 'lib/tst.rb', line 35 def assert_raises(expected=StandardError) begin yield rescue => actual return actual if actual.kind_of?(expected) raise Failure.new("Failure: Unexpected Exception", expected, actual) end raise Failure.new("Failure: No Exception", expected, "Nothing raised.") end |