standard_assert
standard_assert is a Standard Library-like library for assertions in Ruby.
It is aimed at encouraging us to use assertion methods anywhere; Not only testing but also production.
Installation
Add this line to your application's Gemfile:
gem 'standard_assert'
And then execute:
$ bundle
Usage
Use Assert module with extend or include in classes or modules where you want to use assertion methods:
require 'standard_assert'
module MyMath
extend ::Assert
module_function
def abs(num)
assert_instance_of([::Float, ::Integer, ::Rational], num)
num.positive? ? num : -num
end
end
MyMath.abs('42')
#=> AssertionError: <"42"> was expected to be instance_of?
# [<Float>, <Integer>, <Rational>] but was
# <String>.
Contributing
You should follow the steps below.
- Fork the repository
- Create a feature branch:
git checkout -b add-new-feature - Commit your changes:
git commit -am 'Add new feature' - Push the branch:
git push origin add-new-feature - Send us a pull request
License
The gem is available as open source under the terms of the MIT License.