Class Index [+]

Quicksearch

Spec::Mocks::ArgumentMatchers

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.

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
with(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)

     # File lib/spec/mocks/argument_matchers.rb, line 158
158:       def any_args
159:         AnyArgsMatcher.new
160:       end
with(anything()) click to toggle source

Passes as long as there is an argument.

     # File lib/spec/mocks/argument_matchers.rb, line 166
166:       def anything
167:         AnyArgMatcher.new(nil)
168:       end
with(boolean()) click to toggle source

Passes if the argument is boolean.

     # File lib/spec/mocks/argument_matchers.rb, line 190
190:       def boolean
191:         BooleanMatcher.new(nil)
192:       end
with(duck_type(:hello, :goodbye)) click to toggle source

Passes if the argument responds to the specified messages.

Examples

  array = []
  display = mock('display')
  display.should_receive(:present_names).with(duck_type(:length, :each))
  => passes
     # File lib/spec/mocks/argument_matchers.rb, line 182
182:       def duck_type(*args)
183:         DuckTypeMatcher.new(*args)
184:       end
hash_including(*args) click to toggle source

:call-seq:

  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 includes the specified key(s) or key/value pairs. If the hash includes other keys, it will still pass.

     # File lib/spec/mocks/argument_matchers.rb, line 200
200:       def hash_including(*args)
201:         HashIncludingMatcher.new(anythingize_lonely_keys(*args))
202:       end
with(hash_not_including(:key, :key2 => :val2)) click to toggle source

Passes if the argument is a hash that doesn’t include the specified key(s) or key/value

     # File lib/spec/mocks/argument_matchers.rb, line 210
210:       def hash_not_including(*args)
211:         HashNotIncludingMatcher.new(anythingize_lonely_keys(*args))
212:       end
instance_of(klass) click to toggle source

Passes if arg.instance_of?(klass)

     # File lib/spec/mocks/argument_matchers.rb, line 215
215:       def instance_of(klass)
216:         InstanceOf.new(klass)
217:       end
Also aliased as: an_instance_of
kind_of(klass) click to toggle source

Passes if arg.kind_of?(klass)

     # File lib/spec/mocks/argument_matchers.rb, line 222
222:       def kind_of(klass)
223:         KindOf.new(klass)
224:       end
Also aliased as: a_kind_of
with(no_args()) click to toggle source

Passes if no arguments are passed along with the message

     # File lib/spec/mocks/argument_matchers.rb, line 149
149:       def no_args
150:         NoArgsMatcher.new
151:       end

Private Instance Methods

anythingize_lonely_keys(*args) click to toggle source
     # File lib/spec/mocks/argument_matchers.rb, line 230
230:       def anythingize_lonely_keys(*args)
231:         hash = args.last.class == Hash ? args.delete_at(1) : {}
232:         args.each { | arg | hash[arg] = anything }
233:         hash
234:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.