Module | RSpec::Mocks::ArgumentMatchers |
In: |
lib/rspec/mocks/argument_matchers.rb
|
ArgumentMatchers are messages that you can include in message expectations to match arguments against a broader check than simple equality.
With the exception of any_args() and no_args(), the matchers are all positional - they match against the arg in the given position.
Passes if object receives :message with any args at all. This is really a more explicit variation of object.should_receive(:message)
object.should_receive(:message).with(any_args())
Passes if the argument responds to the specified messages.
object.should_receive(:message).with(duck_type(:hello)) object.should_receive(:message).with(duck_type(:hello, :goodbye))
Passes if the argument is a hash that includes the specified key(s) or key/value pairs. If the hash includes other keys, it will still pass.
object.should_receive(:message).with(hash_including(:key => val)) object.should_receive(:message).with(hash_including(:key)) object.should_receive(:message).with(hash_including(:key, :key2 => val2))
Passes if the argument is a hash that doesn‘t include the specified key(s) or key/value
object.should_receive(:message).with(hash_not_including(:key => val)) object.should_receive(:message).with(hash_not_including(:key)) object.should_receive(:message).with(hash_not_including(:key, :key2 => :val2))