A straightfoward mocking facility. Typically used in test cases. The Mock class offers a few constructors fro quickly building mockups.

  mock - Returns a static reponse.
  echo - Returns the arguments passed-in.
  spin - Returns a rotation of reponses.
  keys - Returns an index of responses.

Mock classes can be built from sratch or partially framed against other classes.

Usage

  class ContextMock < Mock
    mock :response_headers, {}
    spin :host_url, ['http://www.nitrohq.com','http://www.rubyforge.com']
  end

  ctx = ContextMock.new
  ctx.response_headers['location'] = url
  ctx.host_url   #=> "http://www.nitrohq.com"
  ctx.host_url   #=> "http://www.rubyforge.com"

Or

  class ContextMock < Mock(Context)
    ...
  end
Methods
Constants
UnmockedMethods = %r{^( |inspect |kind_of\?|is_a\?|instance_of\?|class |method|send|respond_to\? |hash |__ )}x
  Certain methods are not mocked:
  inspect       (tricky)
  class         (delegated)
  kind_of?      (delegated)
  is_a?         (delegated)
  instance_of?  (delegated)
  method        (works as-is)
  send          (works as-is)
  respond_to?   (works as-is)
  hash          (no way to mock)

  __id__, __call__, etc. (not meant to be mocked, ever!)
Attributes
[R] mocked_class
Public Class methods
echo( sym ) [ source ]

Responds with input.

keys( sym, hsh ) [ source ]

Responds according to a mapping of input parameters.

mock( sym, val ) [ source ]

Mock a static repsonse.

mocks() [ source ]
spin( sym, arr ) [ source ]

Reponds with a rotation of reponses.