Instead of the simple assert and refute methods for making basic assertions, the assert library consists of two classes: Assertion and BlockAssertion. These classes define various methods for making the actual assertions, all of which use a fluid design to make writing assertions in test code clean and easy.
The assert library is automatically included with spec, and the entire set of Myst specs have been refactored to use it appropriately.
In total, the methods added by this PR are:
Assertion#equals (alias Assertion#==)
Assertion#does_not_equal (alias Assertion#!=)
Assertion#less_than (alias Assertion#<)
Assertion#less_or_equal (alias Assertion#<=)
Assertion#greater_or_equal (alias Assertion#>=)
Assertion#greater_than (alias Assertion#>)
Assertion#between
BlockAssertion#raises
BlockAssertion#succeeds
BlockAssertion#returns
BlockAssertion#called_with_arguments
To access these methods, the library also adds two clauses of an assert method, which takes care of instantiating the right type of object for the assertions being made.
For assertions on static values, just use assert(some_argument), then call the appropriate method for the assertion. For example:
assert(1).equals(1)
assert(1) != 2
For assertions on dynamic values, or about what happens during the execution of a method, use the block form of assert{ some_block_code }:
When an assertion does not pass, it will raise an AssertionFailure object with relevant information about the failure. Inside of the spec library, this is automatically printed out to the console with additional location information.
Instead of the simple
assert
andrefute
methods for making basic assertions, theassert
library consists of two classes:Assertion
andBlockAssertion
. These classes define various methods for making the actual assertions, all of which use a fluid design to make writing assertions in test code clean and easy.The
assert
library is automatically included withspec
, and the entire set of Myst specs have been refactored to use it appropriately.In total, the methods added by this PR are:
Assertion#equals
(aliasAssertion#==
)Assertion#does_not_equal
(aliasAssertion#!=
)Assertion#less_than
(aliasAssertion#<
)Assertion#less_or_equal
(aliasAssertion#<=
)Assertion#greater_or_equal
(aliasAssertion#>=
)Assertion#greater_than
(aliasAssertion#>
)Assertion#between
BlockAssertion#raises
BlockAssertion#succeeds
BlockAssertion#returns
BlockAssertion#called_with_arguments
To access these methods, the library also adds two clauses of an
assert
method, which takes care of instantiating the right type of object for the assertions being made.For assertions on static values, just use
assert(some_argument)
, then call the appropriate method for the assertion. For example:For assertions on dynamic values, or about what happens during the execution of a method, use the block form of
assert{ some_block_code }
:When an assertion does not pass, it will raise an
AssertionFailure
object with relevant information about the failure. Inside of the spec library, this is automatically printed out to the console with additional location information.