module RSpec::Mocks::ArgumentMatchers

def self.anythingize_lonely_keys(*args)

Other tags:
    Private: -
def self.anythingize_lonely_keys(*args)
  hash = Hash === args.last ? args.delete_at(-1) : {}
  args.each { | arg | hash[arg] = AnyArgMatcher::INSTANCE }
  hash
end

def any_args

object.message(1, 2, 3, 4)
object.message(1, 2, 3)
object.message(1, 2)
# matches any of these:

expect(object).to receive(:message).with(1, 2, any_args)
@example

Acts like an arg splat, matching any number of args at any point in an arg list.
def any_args
  AnyArgsMatcher::INSTANCE
end

def anything

expect(object).to receive(:message).with(anything)
@example

Matches any argument at all.
def anything
  AnyArgMatcher::INSTANCE
end

def array_including(*args)

expect(object).to receive(:message).with(array_including([1,2,3]))
expect(object).to receive(:message).with(array_including(1,2,3))
@example

Ignores duplicates and additional values
Matches an array that includes the specified items at least once.
def array_including(*args)
  actually_an_array = Array === args.first && args.count == 1 ? args.first : args
  ArrayIncludingMatcher.new(actually_an_array)
end

def boolean

expect(object).to receive(:message).with(boolean())
@example

Matches a boolean value.
def boolean
  BooleanMatcher::INSTANCE
end

def duck_type(*args)

expect(object).to receive(:message).with(duck_type(:hello, :goodbye))
expect(object).to receive(:message).with(duck_type(:hello))
@example

Matches if the actual argument responds to the specified messages.
def duck_type(*args)
  DuckTypeMatcher.new(*args)
end

def hash_excluding(*args)

expect(object).to receive(:message).with(hash_excluding(:key, :key2 => :val2))
expect(object).to receive(:message).with(hash_excluding(:key))
expect(object).to receive(:message).with(hash_excluding(:key => val))
@example

Matches a hash that doesn't include the specified key(s) or key/value.
def hash_excluding(*args)
  HashExcludingMatcher.new(ArgumentMatchers.anythingize_lonely_keys(*args))
end

def hash_including(*args)

expect(object).to receive(:message).with(hash_including(:key, :key2 => val2))
expect(object).to receive(:message).with(hash_including(:key))
expect(object).to receive(:message).with(hash_including(:key => val))
@example

Ignores any additional keys.
Matches a hash that includes the specified key(s) or key/value pairs.
def hash_including(*args)
  HashIncludingMatcher.new(ArgumentMatchers.anythingize_lonely_keys(*args))
end

def instance_of(klass)

expect(object).to receive(:message).with(instance_of(Thing))
@example

Matches if `arg.instance_of?(klass)`
def instance_of(klass)
  InstanceOf.new(klass)
end

def kind_of(klass)

expect(object).to receive(:message).with(kind_of(Thing))
@example

Matches if `arg.kind_of?(klass)`
def kind_of(klass)
  KindOf.new(klass)
end

def no_args

expect(object).to receive(:message).with(no_args)
@example

Matches no arguments.
def no_args
  NoArgsMatcher::INSTANCE
end