RSpec::Mocks::ArgumentMatchers

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.

Public Instance Methods

a_kind_of(klass) click to toggle source
Alias for: kind_of
an_instance_of(klass) click to toggle source
Alias for: instance_of
any_args() click to toggle source

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
140:       def any_args
141:         AnyArgsMatcher.new
142:       end
anything() click to toggle source

Passes as long as there is an argument.

@example

  object.should_receive(:message).with(anything())
     # File lib/rspec/mocks/argument_matchers.rb, line 149
149:       def anything
150:         AnyArgMatcher.new(nil)
151:       end
boolean() click to toggle source

Passes if the argument is boolean.

@example

  object.should_receive(:message).with(boolean())
     # File lib/rspec/mocks/argument_matchers.rb, line 177
177:       def boolean
178:         BooleanMatcher.new(nil)
179:       end
duck_type(*args) click to toggle source

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
168:       def duck_type(*args)
169:         DuckTypeMatcher.new(*args)
170:       end
hash_excluding(*args) click to toggle source

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
201:       def hash_excluding(*args)
202:         HashExcludingMatcher.new(anythingize_lonely_keys(*args))
203:       end
Also aliased as: hash_not_including
hash_including(*args) click to toggle source

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
189:       def hash_including(*args)
190:         HashIncludingMatcher.new(anythingize_lonely_keys(*args))
191:       end
hash_not_including(*args) click to toggle source
Alias for: hash_excluding
instance_of(klass) click to toggle source

Passes if `arg.instance_of?(klass)`

     # File lib/rspec/mocks/argument_matchers.rb, line 208
208:       def instance_of(klass)
209:         InstanceOf.new(klass)
210:       end
Also aliased as: an_instance_of
kind_of(klass) click to toggle source

Passes if `arg.kind_of?(klass)`

     # File lib/rspec/mocks/argument_matchers.rb, line 215
215:       def kind_of(klass)
216:         KindOf.new(klass)
217:       end
Also aliased as: a_kind_of
no_args() click to toggle source

Passes if no arguments are passed along with the message

@example

  object.should_receive(:message).with(no_args)
     # File lib/rspec/mocks/argument_matchers.rb, line 158
158:       def no_args
159:         NoArgsMatcher.new
160:       end

Private Instance Methods

anythingize_lonely_keys(*args) click to toggle source
     # File lib/rspec/mocks/argument_matchers.rb, line 223
223:       def anythingize_lonely_keys(*args)
224:         hash = args.last.class == Hash ? args.delete_at(1) : {}
225:         args.each { | arg | hash[arg] = anything }
226:         hash
227:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.