FlexMock 0.7.0 Released

FlexMock is a flexible mocking library for use in unit testing and behavior specification in Ruby. Version 0.7.0 introduces several enhancements.

New in 0.7.0

New Features Added in 0.6.x

In case you missed them, here are a number of features that were added during the 0.6.x versions of FlexMock.

What is FlexMock?

FlexMock is a flexible framework for creating mock object for testing. When running unit tests, it is often desirable to use isolate the objects being tested from the "real world" by having them interact with simplified test objects. Sometimes these test objects simply return values when called, other times they verify that certain methods were called with particular arguments in a particular order.

FlexMock makes creating these test objects easy.



Suppose you had a Dog object that wagged a tail when it was happy. Something like this:

class Dog
  def initialize(a_tail)
    @tail = a_tail
  def happy

To test the Dog class without a real Tail object (perhaps because real Tail objects activate servos in some robotic equipment), you can do something like this:

require 'test/unit' require 'flexmock/test_unit'

class TestDog < Test::Unit::TestCase
  def test_dog_wags_tail_when_happy
    tail = flexmock("tail")
    dog = Dog.new(tail)

FlexMock will automatically verify that the mocked tail object received the message wag exactly one time. If it doesn't, the test will not pass.

See the FlexMock documentation at flexmock.rubyforge.org for details on specifying arguments and return values on mocked methods, as well as a simple technique for mocking tail objects when the Dog class creates the tail objects directly.


You can make sure you have the latest version with a quick RubyGems command:

gem install flexmock    (you may need root/admin privileges)

Otherwise, you can get it from the more traditional places:



You will find documentation at: flexmock.rubyforge.org.

-- Jim Weirich