Posted By: Jim Weirich
Date: 2007-07-01 22:34
Summary: FlexMock 0.6.2
Project: FlexMock

= FlexMock 0.6.2 Released

FlexMock is a flexible mocking library for use in unit testing and behavior
specification in Ruby. Version 0.6.2 introduces a two minor enhancements.

== New in 0.6.2

* When creating a partial mock using a block, flexmock() now returns
the domain object rather than the mock proxy. This allows the
following to work:

obj = flexmock( { |m| m.should_receive(:hi).once }

for more details.

* The +and_raise+ method is now supported for directly specifying that
exceptions will be thrown from a mock.

== 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.

=== Features

* Easy integration with both Test::Unit and RSpec. Mocks created with the
flexmock method are automatically verified at the end of the test or

* A fluent interface that allows mock behavior to be specified very

* A "record mode" where an existing implementation can record its
interaction with a mock for later validation against a new

* Easy mocking of individual methods in existing, non-mock objects.

* The ability to cause classes to instantiate test instances (instead of real
instances) for the duration of a test.

=== Example

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 =

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

== Availability

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:

-- Jim Weirich

Latest News
TZInfo::Data v1.2014.2 Released
    Philip Ross - 2014-03-25 22:32
TZInfo v0.3.39 Released
    Philip Ross - 2014-03-09 20:23
TZInfo::Data v1.2014.1 Released
    Philip Ross - 2014-03-09 20:00
Automatic Ruby 14.2.0 has been released!
    id 774 - 2014-02-26 06:23
kramdown 1.3.2 released
    Thomas Leitner - 2014-02-16 08:35


Forums | Admin

Discussion Forums: flexmock-0.6.2-release

Start New Thread Start New Thread


Topic Topic Starter Replies Last Post