https://github.com/yasaichi/standard_assert
Standard Library-like library for assertions in Ruby. Encourages us to use assertion methods anywhere.
https://github.com/yasaichi/standard_assert
assert ruby
Last synced: 4 months ago
JSON representation
Standard Library-like library for assertions in Ruby. Encourages us to use assertion methods anywhere.
- Host: GitHub
- URL: https://github.com/yasaichi/standard_assert
- Owner: yasaichi
- License: mit
- Created: 2019-12-14T02:33:35.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-08T10:30:42.000Z (about 4 years ago)
- Last Synced: 2026-02-21T23:53:15.855Z (4 months ago)
- Topics: assert, ruby
- Language: Ruby
- Homepage:
- Size: 30.3 KB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# standard_assert
[](http://badge.fury.io/rb/standard_assert)
[](https://travis-ci.org/yasaichi/standard_assert)
[](https://codeclimate.com/github/yasaichi/standard_assert)
[](https://codeclimate.com/github/yasaichi/standard_assert/coverage)
`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:
```ruby
gem 'standard_assert'
```
And then execute:
```
$ bundle
```
## Usage
Include `Assert` module in a class, and you can use the assertion methods as its private methods:
```ruby
require 'standard_assert'
class Stack
include ::Assert
def initialize
@store = []
end
def pop
assert(!@store.empty?)
@store.pop
end
def push(element)
@store.push(element)
self
end
end
Stack.new.pop #=> AssertionError (Expected false to be truthy.)
```
Or just call them with the module as a receiver:
```ruby
class Stack
def peek
::Assert.assert(!@store.empty?)
@store.last
end
end
Stack.new.peek #=> AssertionError (Expected false to be truthy.)
```
## API
`Assert` provides `aseert` and `assert_*` methods as its module functions.
The method interfaces are basically the same as ones of `minitest` gem except that
they throw not `Minitest::Assertion` but `AssertionError` when an assertion fails.
See also: http://docs.seattlerb.org/minitest/Minitest/Assertions.html
## Contributing
You should follow the steps below.
1. [Fork the repository](https://help.github.com/articles/fork-a-repo/)
2. Create a feature branch: `git checkout -b add-new-feature`
3. Commit your changes: `git commit -am 'Add new feature'`
4. Push the branch: `git push origin add-new-feature`
5. [Send us a pull request](https://help.github.com/articles/about-pull-requests/)
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).