1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
= Mocha {<img src="https://secure.travis-ci.org/floehopper/mocha.png" />}[http://travis-ci.org/floehopper/mocha]
Mocha is a library for mocking and stubbing using a syntax like that of {JMock}[http://www.jmock.org].
It can be used with many testing frameworks e.g. {Test::Unit}[http://www.ruby-doc.org/core/classes/Test/Unit.html], {RSpec}[http://rspec.info/], {test/spec}[http://chneukirchen.org/repos/testspec/README], {expectations}[http://expectations.rubyforge.org/], {Dust}[http://dust.rubyforge.org/], {MiniTest}[http://rubyforge.org/projects/bfts] and even {JtestR}[http://jtestr.codehaus.org/].
Mocha provides a unified, simple and readable syntax for both traditional mocking and partial mocking.
Mocha was harvested from projects at {Reevoo}[http://www.reevoo.com/] by me ({James}[http://jamesmead.org/]) and my (then) colleagues {Ben}[http://www.techbelly.com/], {Chris}[http://chrisroos.co.uk/] and {Paul}[http://po-ru.com/].
== Installation
Install the latest version of the gem with the following command...
$ gem install mocha
Note that if you are intending to use Mocha with Test::Unit or MiniTest, you should only load Mocha *after* loading the relevant test library...
require "test/unit"
require "mocha"
If you're using Bundler, ensure the correct load order by not auto-requiring Mocha in the Gemfile and then later load it once you know the test library has been loaded...
# Gemfile
gem "mocha", :require => false
# Elsewhere after Bundler has loaded gems
require "test/unit"
require "mocha"
Note that versions 0.10.2, 0.10.3 & 0.11.0 included a bug. Please do not use these versions.
Or install the {Rails}[http://www.rubyonrails.org/] plugin...
$ script/plugin install git://github.com/floehopper/mocha.git
Note that versions 0.9.6 & 0.9.7 of the Rails plugin were broken. As of version 0.9.8, you need to explicitly load Mocha after the test framework e.g. by adding "require 'mocha'" at the bottom of test/test_helper.rb.
== Examples
* Quick Start - {file:misc.rb Usage Examples}
* Traditional mocking - {file:mocha.rb Star Trek Example}
* Setting expectations on real classes - {file:stubba.rb Order Example}
* More examples on {James Mead's Blog}[http://jamesmead.org/blog/]
* {Mailing List Archives}[http://groups.google.com/group/mocha-developer]
== Links
* {Source code}[http://github.com/floehopper/mocha]
* {Bug reports}[http://github.com/floehopper/mocha/issues]
== License
Copyright Revieworld Ltd. 2006
You may use, copy and redistribute this library under the same terms as {Ruby itself}[http://www.ruby-lang.org/en/LICENSE.txt] or under the {file:MIT-LICENSE.rdoc MIT license}.
|