Giter Club home page Giter Club logo

mocha's Introduction

Mocha is a library for mocking and stubbing using a syntax like that of JMock.

It can be used with many testing frameworks e.g. Test::Unit, RSpec, test/spec, expectations, Dust, MiniTest and even JtestR.

Mocha provides a unified, simple and readable syntax for both traditional mocking and partial mocking.

Mocha was harvested from projects at Reevoo by me (James) and my (then) colleagues Ben, Chris and Paul.

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 plugin…

$ script/plugin install git://github.com/freerange/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

  • Mailing List Archives

Developing Mocha

  • Fork

  • Develop in a branch

  • Ensure all the tests run against all supported versions of test/unit and minitest by running ./build-matrix.rb

  • Issue a pull request from your fork/branch

License

Copyright Revieworld Ltd. 2006

You may use, copy and redistribute this library under the same terms as Ruby itself or under the {file:MIT-LICENSE.rdoc MIT license}.

mocha's People

Contributors

alloy avatar bira avatar blt avatar chrisroos avatar dan-manges avatar denisdefreyne avatar floehopper avatar julik avatar lukeredpath avatar meineerde avatar nicklewis avatar reddavis avatar sikachu avatar sprsquish avatar stevenyxu avatar taylorbarstow avatar thewoolleyman avatar threedaymonk avatar tinogomes avatar viking avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.