Expresenter

Build Status Code Climate Gem Version Inline docs Documentation

Expectation result presenter.

Installation

Add this line to your application's Gemfile:

gem "expresenter"

And then execute:

$ bundle

Or install it yourself as:

$ gem install expresenter

Usage

Assuming that an expectation is an assertion that is either true or false, qualifying it with MUST, SHOULD and MAY, we can draw up several scenarios:

Requirement levels MUST SHOULD MAY
Implemented & Matched true true true
Implemented & Not matched false true false
Implemented & Exception false false false
Not implemented false false true

Then,

  • for a true assertion, a Expresenter::Pass instance can be returned;
  • for a false assertion, a Expresenter::Fail exception can be raised.

Both class share a common interface.

Passed expectations can be classified as:

  • ✅ success
  • ⚠️ warning
  • 💡 info

Failed expectations can be classified as:

  • ❌ failure
  • 💥 error

Example

result = Expresenter.call(true).with(actual: "FOO", error: nil, expected: "foo", got: true, negate: true, valid: true, matcher: :eql, level: :MUST)

result.failed? # => false
result.failure? # => false
result.info? # => false
result.warning? # => false
result.to_sym # => :success
result.char # => "."
result.emoji # => "✅"
result.passed? # => true
result.negate? # => true
result.error? # => false
result.success? # => true
result.valid? # => true
result.inspect # => "Expresenter::Pass(actual: \"FOO\", error: nil, expected: \"foo\", got: true, matcher: :eql, negate: true, level: :MUST, valid: true)"
result.definition # => "eql \"foo\""
result.maybe_negate # => " not"
result.summary # => "expected \"FOO\" not to eql \"foo\""
result.colored_char # => "\e[32m.\e[0m"
result.colored_string # => "\e[32mSuccess: expected \"FOO\" not to eql \"foo\".\e[0m"
result.message # => "Success: expected \"FOO\" not to eql \"foo\"."
result.to_s # => "Success: expected \"FOO\" not to eql \"foo\"."
result.titre # => "Success"

More Examples

A full list of unit tests can be viewed (and executed) here: ./test.rb

Contact

Rubies

Versioning

Expresenter follows Semantic Versioning 2.0.

License

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


This project is sponsored by:
Sashite