Project

covenant

0.0
No commit activity in last 3 years
No release in over 3 years
Assertion library for Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 2.11

Runtime

~> 0.6.0.pre
 Project Readme

Covenant

Covenant is an assertion library for Ruby, designed to be used in your production code.

It adds 2 methods to Object: assert and asserting.

Usage

If you want to make the DSL available globally, simply call Covenant.abide. Otherwise, call Covenant.abide <target obj>. You can also register the DSL methods with different names, if you don't like to use the names provided. For example, if you want to make the DSL available globally, but you'd rather use uphold and upholding as the method names, call Covenant.abide Object, [:uphold, :upholding].

To enforce some condition, pass a block to #assert. The block's result must be truthy, otherwise an exception will be raised.

assert { [].is_a?(Array) } # yay
assert { 1.is_a?(String) } # oh, noes!

assert returns its receiver, so you can use it with a method's return value:

obj.assert { obj > 1 } #=> obj

In this case, you'll probably want to use asserting as it reads slightly better:

obj.asserting { obj > 1 } #=> obj

assert will optionally yield its receiver to the block.

some_query.asserting { |obj| obj > 1 } #=> result

In the last case, obj is the return value of #some_query.

Supported Ruby versions

Tested on Ruby 1.9. It may work on 1.8 but I don't guarantee it.

TODO

  • Document