Kagemusha - A Testing Mock-Objects Library

github.com/nayutaya/kagemusha/

DESCRIPTION:

Kagemusha is a library of helper functions for testing Ruby scripts. It helps you generating scoped mock-objects which overrides the behavior of a class only in a given blocks, without tainting a global area.

For example, if you override Date.today when you are writing something about dates, then the code will taint global areas involuntarily.

But if you use Kagemusha, the test code will override the behavior of the class only in the given block.

Example:

require "kagemusha"

musha = Kagemusha.new(Time)
musha.defs(:now) { self.local(2000, 1, 1) }
musha.def(:to_s) { self.strftime("%Y-%m-%d") } 

musha.swap {
  p Time.now      #=> Sat Jan 01 00:00:00 +0900 2000
  p Time.now.to_s #=> "2000-01-01"
}

Also, it has some default useful mock-objects set include Date, Time and rand.

Example:

require "kagemusha/date"

musha = Kagemusha::Date.at(2000, 1, 1)
musha.swap {
  p Date.today.to_s #=> "2000-01-01"
}

SYNOPSIS:

See the example directory.

INSTALL:

The easiest way to get started with Kagemusha is to install it via RubyGems. You can do this easily:

$ gem install nayutaya-kagemusha

LICENSE:

Ruby’s License

SUPPORT:

Contact me.

Yuya Kato <yuyakato at gmail.com>