Project

mocoso

No commit activity in last 3 years
No release in over 3 years
A simple stub & mock library.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.2
~> 11.0
~> 0.39
 Project Readme

Mocoso Build Status

Yet Another Simple Stub & Mock library. This is inspired by Minitest::Mock and Override.

Description

Mocoso meets the following criteria:

  • Simplicity.
  • Always restore stubbed methods to their original implementations.
  • Doesn't allow to stub or mock undefined methods.
  • Doesn't monkey-patch any class or object.
  • Test-framework agnostic. No integration code.

Installation

Add this line to your application's Gemfile:

gem "mocoso"

And then execute:

$ bundle

Or install it yourself as:

$ gem install mocoso

Usage

A quick example (uses Cutest):

require "cutest"
require "mocoso"

include Mocoso

test "mocking a class method" do
  user = User.new

  expect(User, :find, with: [1], return: user) do
    assert_equal user, User.find(1)
  end

  assert_equal nil, User.find(1)
end

test "stubbing an instance method" do
  user = User.new

  stub(user, :valid?, true) do
    assert user.valid?
  end

  assert !user.valid?
end

Check Official Documentation for more details.

Contributing

Fork the project with:

$ git clone git@github.com:frodsan/mocoso.git

To install dependencies, use:

$ bundle install

To run the test suite, do:

$ rake test

For bug reports and pull requests use GitHub.

License

Mocoso is released under the MIT License.