Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kddnewton/minitest-keyword

Use Minitest assertions with keyword arguments
https://github.com/kddnewton/minitest-keyword

Last synced: about 2 months ago
JSON representation

Use Minitest assertions with keyword arguments

Awesome Lists containing this project

README

        

# Minitest::Keyword

[![Build Status](https://github.com/kddnewton/minitest-keyword/workflows/Main/badge.svg)](https://github.com/kddnewton/minitest-keyword/actions)
[![Gem Version](https://img.shields.io/gem/v/minitest-keyword.svg)](https://rubygems.org/gems/minitest-keyword)

A small gem for allowing you to use Minitest assertions with keyword arguments. No longer worry about remembering the order of arguments!

## Installation

Add this line to your application's Gemfile:

```ruby
gem "minitest-keyword"
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install minitest-keyword

## Usage

Add `require "minitest/keyword"` to your `test_helper.rb` script. In your tests you will now be able to change your assertions from:

```ruby
assert_equal "foo", foo.inspect
```

to:

```ruby
assert_equal expected: "foo", actual: foo.inspect
```

All of the standard Minitest assertions can now be used with keyword arguments. Note that this gem is still backwards-compatible with Minitest itself, so your existing tests won't break.

## Cheat Sheet

The actual keyword method creation is done through introspection, but the equivalent method signatures are listed below. Note that when you see `message: nil` it effectively means that you can pass through a message or it will use whatever standard Minitest message is configured for that assertion.

```ruby
assert test:, message: nil
assert_empty object:, message: nil
assert_equal expected:, actual:, message: nil
assert_in_delta expected:, actual:, delta: 0.001, message: nil
assert_in_epsilon expected:, actual:, epsilon: 0.001, message: nil
assert_includes collection:, object:, message: nil
assert_instance_of class:, object:, message: nil
assert_kind_of class:, object:, message: nil
assert_match matcher:, object:, message: nil
assert_nil object:, message: nil
assert_operator receiver:, operator:, argument: Minitest::Assertions::UNDEFINED, message: nil
assert_output stdout: nil, stderr: nil
assert_path_exists path:, message: nil
assert_predicate receiver:, operator:, message: nil
assert_raises expected: []
assert_respond_to object:, method:, message: nil, include_all: false
assert_same expected:, actual:, message: nil
assert_throws symbol:, message: nil
```

The associated refutations are also overridden, with the below signatures.

```ruby
refute test:, message: nil
refute_empty object:, message: nil
refute_equal expected:, actual:, message: nil
refute_in_delta expected:, actual:, delta: 0.001, message: nil
refute_in_epsilon expected:, actual:, epsilon: 0.001, message: nil
refute_includes collection:, object:, message: nil
refute_instance_of class:, object:, message: nil
refute_kind_of class:, object:, message: nil
refute_match matcher:, object:, message: nil
refute_nil object:, message: nil
refute_operator receiver:, operator:, argument: Minitest::Assertions::UNDEFINED, message: nil
refute_path_exists path:, message: nil
refute_predicate receiver:, operator:, message: nil
refute_respond_to object:, method:, message: nil, include_all: false
refute_same expected:, actual:, message: nil
```

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kddnewton/minitest-keyword.

## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).