module Mocha::API

Methods added to Test::Unit::TestCase, Minitest::Unit::TestCase or equivalent. The mock creation methods are {#mock}, {#stub} and {#stub_everything}, all of which return a #{Mock} which can be further modified by {Mock#responds_like} and {Mock#responds_like_instance_of} methods, both of which return a {Mock}, too, and can therefore, be chained to the original creation methods.

{Mock#responds_like} and {Mock#responds_like_instance_of} force the mock to indicate what it is supposed to be mocking, thus making it a safer verifying mock. They check that the underlying responder will actually respond to the methods being stubbed, throwing a NoMethodError upon invocation otherwise.

@example Verifying mock using {Mock#responds_like_instance_of}

class Sheep
  def initialize
    raise "some awkward code we don't want to call"
  end
  def chew(grass); end
end

sheep = mock('sheep').responds_like_instance_of(Sheep)
sheep.expects(:chew)
sheep.expects(:foo)
sheep.respond_to?(:chew) # => true
sheep.respond_to?(:foo) # => false
sheep.chew
sheep.foo # => raises NoMethodError exception