Skip to content
Mocha is a mocking and stubbing library for Ruby (canonical repo is now at
Ruby JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


= Mocha

Mocha is a library for mocking and stubbing using a syntax like that of JMock[], and SchMock[]. Most commonly Mocha is used in conjunction with Test::Unit[], but it can be used in other contexts.

One of its main advantages is that it allows you to mock and stub methods on _real_ (non-mock) classes and instances. You can for example stub ActiveRecord[] instance methods like +create+, +save+, +destroy+ and even class methods like +find+ to avoid hitting the database in unit tests.

Mocha provides a unified, simple and readable syntax for both traditional mocking and for mocking with _real_ objects.

Mocha has been harvested from projects at Reevoo[] by me (James[]) and my colleagues Ben[], Chris[] and Paul[]. Mocha is in use on real-world Rails[] projects.

== Download and Installation

Install the gem with the following command...

  $ gem install mocha
Or install the Rails[] plugin...

  $ script/plugin install svn://

Or download Mocha from here -

== Examples

* Quick Start - {Usage Examples}[link:examples/misc.html]
* Traditional mocking - {Star Trek Example}[link:examples/mocha.html]
* Setting expectations on real classes - {Order Example}[link:examples/stubba.html]
* More examples on {Floehopper's Blog}[]
* {Mailing List Archives}[]

== License

Copyright Revieworld Ltd. 2006
You may use, copy and redistribute this library under the same terms as {Ruby itself}[] or under the {MIT license}[].
Something went wrong with that request. Please try again.