Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/toptal/rspec-any_of

any_of/all_of argument matcher for RSpec
https://github.com/toptal/rspec-any_of

rspec rspec-custom-matchers rspec-matchers

Last synced: 25 days ago
JSON representation

any_of/all_of argument matcher for RSpec

Awesome Lists containing this project

README

        

= RSpec `any_of`/`all_of` argument matchers

Argument matchers accepting a list of allowed arguments:

- Liberal `any_of` argument inclusion matcher
- Strict `all_of` argument inclusion matcher

== Installation

Add `gem 'rspec-any_of'` to `Gemfile` and run `bundle`.

== Usage

Add the following to your `spec/spec_helper.rb`:

[source,ruby]
----
require 'rspec/any_of'

RSpec.configure do |config|
# ...
config.include RSpec::AnyOf
end
----

Using `rspec-any_of` you can make flexible expectations on method call arguments.

[source,ruby]
----
it 'sends greetings to chat' do
expect(Chat)
.to receive(:message)
.with(all_of('Hello', 'My name is Phil')).twice

# The only option normally is to be more verbose.
# This is the most optimistic example, with more arguments it's getting noticeably worse.
expect(Chat)
.to receive(:message).with('Hello')
.and receive(:message).with('My name is Phil')
end

it 'greets' do
expect(Greeter)
.to receive(:greet)
.with(any_of('hello', 'good bye'))

# Or, normally:
expect(Greeter)
.to receive(:greet)
.with(eq('hello').or(eq('good bye')))
end
----

== Development

Check out the repo, run `bundle` to install dependencies.
Make your change, run `rspec`, `rubocop` to check the style, and `yardoc` to make sure documentation is correct.

== Contributing

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the https://www.contributor-covenant.org[Contributor Covenant] code of conduct.

Bug reports and pull requests are welcome https://github.com/toptal/rspec-any_of/issues[on GitHub].

== License

https://opensource.org/licenses/MIT[MIT License].