#48 new
David Chelimsky

add invokes(&block) to support fakes

Reported by David Chelimsky | May 13th, 2009 @ 02:40 PM

The "fake" pattern (http://xunitpatterns.com/Fake%20Object.html) is an extension of stub where the method is actually implemented (by the tester) rather than simply returning a canned value.

The attached patch supports the following:

obj = stub()
obj.stubs(:foo).invokes do |bar|
  if bar == :one_thing
    :value_for_one_thing
  else
    :value_for_anything_else
  end
end

This allows you to handle multiple and differing calls to the same method in a single, clear, explicit declaration.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

A mocking & stubbing library for Ruby.

* <a href="http://github.com/floehopper/mocha">GitHub repository</a>
* <a href="http://mocha.rubyforge.org">Documentation</a>
* <a href="http://groups.google.com/group/mocha-developer">Mailing List</a>

People watching this ticket

Attachments

Pages