0.0
No release in over 3 years
Low commit activity in last 3 years
`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.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.17
~> 10.0
>= 0
~> 3.0

Runtime

>= 5.0
 Project Readme

standard_assert

Gem Version Build Status Code Climate Test 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:

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:

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:

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
  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

License

The gem is available as open source under the terms of the MIT License.