Assit is a small and simple assertion framework for Ruby. It’s not yet grown up, but it’s already useful.
Getting started is real easy: Once you have installed assit, you just have to require 'assit'
and start using assertions in your code, e.g. assit { some_codition }
Assertions are directly available in each object; the name of the assertion methods start with ‘assit’, in order not to conflict with the unit testing assertions. There are several assit_*
methods and if applicable they will behave like their counterparts in the unit testing framework.
To get a list of the Assertion methods, see Assit::Assertions.
The assertions are part of the Object
class by design, to make them really easy to use.
The simple #assit takes a simple boolean parameter, that checks if the assertion is true or false.
However, if you use a complex expression for your assertion (like: assit(complex_expression)
you should prefer the assit_block { complex_expression } syntax. In this case the <tt>complex_expression
will also be disabled when you disable the assertions.
If an assertion fails, some kind of action will be taken - e.g. an exception will be raised, or something will be printed to stdout. You can configure the action; if you don’t assit will try and use a method that is useful in most cases. You can also disable assertions completely. In this case, no checks will be done and the overhead during runtime will be minimal. See the documentation of the Assit::Config module for more information.
Assertions allow you to test your code for errors during runtime. This is especially helpful for Ruby, since it doesn’t have any compile-time check. Often a few well-placed assertions can save you a lot of debbuging trouble.
Assertions should check for conditions in the code that indicate ”‘programming errors”’. They are not meant to check for error conditions, nor are they a replacement for unit tests.