Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

153 lines (110 sloc) 6.371 kb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>
File: README
&mdash; Mocha 0.11.3
</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
relpath = '';
if (relpath != '') relpath += '/';
</script>
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
</head>
<body>
<script type="text/javascript" charset="utf-8">
if (window.top.frames.main) document.body.className = 'frames';
</script>
<div id="header">
<div id="menu">
<a href="_index.html" title="Index">Index</a> &raquo;
<span class="title">File: README</span>
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>
<div id="search">
<a id="class_list_link" href="#">Class List</a>
<a id="method_list_link" href="#">Method List</a>
<a id="file_list_link" href="#">File List</a>
</div>
<div class="clear"></div>
</div>
<iframe id="search_frame"></iframe>
<div id="content"><div id='filecontents'>
<h1>Mocha <a href="http://travis-ci.org/floehopper/mocha"><img src="https://secure.travis-ci.org/floehopper/mocha.png" /></a></h1>
<p>Mocha is a library for mocking and stubbing using a syntax like that of <a
href="http://www.jmock.org">JMock</a>.</p>
<p>It can be used with many testing frameworks e.g. <a
href="http://www.ruby-doc.org/core/classes/Test/Unit.html">Test::Unit</a>,
<a href="http://rspec.info/">RSpec</a>, <a
href="http://chneukirchen.org/repos/testspec/README">test/spec</a>, <a
href="http://expectations.rubyforge.org/">expectations</a>, <a
href="http://dust.rubyforge.org/">Dust</a>, <a
href="http://rubyforge.org/projects/bfts">MiniTest</a> and even <a
href="http://jtestr.codehaus.org/">JtestR</a>.</p>
<p>Mocha provides a unified, simple and readable syntax for both traditional
mocking and partial mocking.</p>
<p>Mocha was harvested from projects at <a
href="http://www.reevoo.com/">Reevoo</a> by me (<a
href="http://jamesmead.org/">James</a>) and my (then) colleagues <a
href="http://www.techbelly.com/">Ben</a>, <a
href="http://chrisroos.co.uk/">Chris</a> and <a
href="http://po-ru.com/">Paul</a>.</p>
<h2>Installation</h2>
<p>Install the latest version of the gem with the following command…</p>
<pre class="code ruby"><code>$ gem install mocha</code></pre>
<p>Note that if you are intending to use Mocha with Test::Unit or MiniTest,
you should only load Mocha <b>after</b> loading the relevant test library…</p>
<pre class="code ruby"><code><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>test/unit</span><span class='tstring_end'>&quot;</span></span>
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>mocha</span><span class='tstring_end'>&quot;</span></span></code></pre>
<p>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…</p>
<pre class="code ruby"><code><span class='comment'># Gemfile
</span><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>mocha</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='symbol'>:require</span> <span class='op'>=&gt;</span> <span class='kw'>false</span>
<span class='comment'># Elsewhere after Bundler has loaded gems
</span><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>test/unit</span><span class='tstring_end'>&quot;</span></span>
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>mocha</span><span class='tstring_end'>&quot;</span></span></code></pre>
<p>Note that versions 0.10.2, 0.10.3 &amp; 0.11.0 included a bug. Please do
not use these versions.</p>
<p>Or install the <a href="http://www.rubyonrails.org/">Rails</a> plugin…</p>
<pre class="code ruby"><code>$ script/plugin install git://github.com/floehopper/mocha.git</code></pre>
<p>Note that versions 0.9.6 &amp; 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.</p>
<h2>Examples</h2>
<ul><li>
<p>Quick Start - <a href="file.misc.html" title="Usage Examples">Usage Examples</a></p>
</li><li>
<p>Traditional mocking - <a href="file.mocha.html" title="Star Trek Example">Star Trek Example</a></p>
</li><li>
<p>Setting expectations on real classes - <a href="file.stubba.html" title="Order Example">Order Example</a></p>
</li><li>
<p>More examples on <a href="http://jamesmead.org/blog/">James Mead’s Blog</a></p>
</li><li>
<p><a href="http://groups.google.com/group/mocha-developer">Mailing List
Archives</a></p>
</li></ul>
<h2>Links</h2>
<ul><li>
<p><a href="http://github.com/floehopper/mocha">Source code</a></p>
</li><li>
<p><a href="http://github.com/floehopper/mocha/issues">Bug reports</a></p>
</li></ul>
<h2>License</h2>
<p>Copyright Revieworld Ltd. 2006</p>
<p>You may use, copy and redistribute this library under the same terms as <a
href="http://www.ruby-lang.org/en/LICENSE.txt">Ruby itself</a> or under the
<a href="file.MIT-LICENSE.html" title="MIT license">MIT license</a>.</p>
</div></div>
<div id="footer">
Generated on Wed Apr 25 16:51:30 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.7.5 (ruby-1.9.3).
</div>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.