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
:
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.
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 Contributor Covenant code of conduct.
Bug reports and pull requests are welcome on GitHub.