Module: RSpec::AnyOf

Defined in:
lib/rspec/any_of.rb,
lib/rspec/any_of/version.rb

Overview

Provides argument matchers accepting a list of allowed arguments.

Constant Summary collapse

VERSION =
'1.0.0'.freeze

Instance Method Summary collapse

Instance Method Details

#all_of(*required_arguments) ⇒ Object

Strict argument inclusion matcher. Should be used with countable qualifier.

Examples:

expect(Chat)
  .to receive(:message)
  .with(all_of('Hello', 'My name is Phil')).twice

Parameters:

  • required_arguments (Array<Object>)

    required arguments



35
36
37
38
39
40
41
42
43
44
# File 'lib/rspec/any_of.rb', line 35

RSpec::Matchers.define :all_of do |*expected|
  description do
    "all of #{expected}"
  end

  match do |actual|
    @expected ||= expected.dup
    expect(@expected.delete(actual)).not_to be_nil
  end
end

#any_of(*allowed_arguments) ⇒ Object

Liberal argument inclusion matcher.

Examples:

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

Parameters:

  • allowed_arguments (Array<Object>)

    allowed arguments



15
16
17
18
19
20
21
22
23
# File 'lib/rspec/any_of.rb', line 15

RSpec::Matchers.define :any_of do |*expected|
  description do
    "any of #{expected}"
  end

  match do |actual|
    expected.include?(actual)
  end
end