ArgumentMatchers are placeholders 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`, they all match against the arg in same position in the argument list.
Passes if object receives `:message` with any args at all. This is really a more explicit variation of `object.should_receive(:message)`
@example
object.should_receive(:message).with(any_args())
# File lib/rspec/mocks/argument_matchers.rb, line 140 def any_args AnyArgsMatcher.new end
Passes as long as there is an argument.
@example
object.should_receive(:message).with(anything())
# File lib/rspec/mocks/argument_matchers.rb, line 149 def anything AnyArgMatcher.new(nil) end
Passes if the argument is boolean.
@example
object.should_receive(:message).with(boolean())
# File lib/rspec/mocks/argument_matchers.rb, line 177 def boolean BooleanMatcher.new(nil) end
Passes if the argument responds to the specified messages.
@example
object.should_receive(:message).with(duck_type(:hello)) object.should_receive(:message).with(duck_type(:hello, :goodbye))
# File lib/rspec/mocks/argument_matchers.rb, line 168 def duck_type(*args) DuckTypeMatcher.new(*args) end
Passes if the argument is a hash that doesn't include the specified key(s) or key/value
@example
object.should_receive(:message).with(hash_excluding(:key => val)) object.should_receive(:message).with(hash_excluding(:key)) object.should_receive(:message).with(hash_excluding(:key, :key2 => :val2))
# File lib/rspec/mocks/argument_matchers.rb, line 201 def hash_excluding(*args) HashExcludingMatcher.new(anythingize_lonely_keys(*args)) end
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.
@example
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))
# File lib/rspec/mocks/argument_matchers.rb, line 189 def hash_including(*args) HashIncludingMatcher.new(anythingize_lonely_keys(*args)) end
Passes if `arg.instance_of?(klass)`
# File lib/rspec/mocks/argument_matchers.rb, line 208 def instance_of(klass) InstanceOf.new(klass) end
Passes if `arg.kind_of?(klass)`
# File lib/rspec/mocks/argument_matchers.rb, line 215 def kind_of(klass) KindOf.new(klass) end
Generated with the Darkfish Rdoc Generator 2.