= Flex Mock -- Making Mock Easy

FlexMock is a simple mock object for unit testing.  The interface is
simple, but still provides a good bit of flexibility.

= Links

<b>Documents</b>   :: http://onestepback.org/software/flexmock
<b>Download</b>    :: Use RubyGems to download the flexmock gem from http://gems.rubyforge.org

== Installation

You can install FlexMock with the following command.

 $ gem install flexmock

== Simple Example

We have a data acquisition class (+TemperatureSampler+) that reads a
temperature sensor and returns an average of 3 readings.  We don't
have a _real_ temperature to use for testing, so we mock one up with a
mock object that responds to the +read_temperature+ message.

Here's the complete example:

  class TemperatureSampler
    def initialize(sensor)
      @sensor = sensor
    end

    def average_temp
      total = (0...3).collect { @sensor.read_temperature }.inject { |i, s| i + s }
      total / 3.0
    end
  end

  class TestTemperatureSampler < Test::Unit::TestCase
    def test_tempurature_sampler
      readings = [10, 12, 14]
      mock_sensor = FlexMock.new
      mock_sensor.mock_handle(:read_temperature) { readings.shift }
      sampler = TemperatureSampler.new(mock_sensor)
      assert_equal 12, sampler.average_temp
    end
  end

== Other Mock Objects

ruby-mock      :: http://www.b13media.com/dev/ruby/mock.html
test-unit-mock :: http://www.deveiate.org/code/Test-Unit-Mock.shtml

== License

Copyright 2003, 2004 by Jim Weirich (jim@weirichhouse.org).
All rights reserved.

Permission is granted for use, copying, modification, distribution,
and distribution of modified versions of this work as long as the
above copyright notice is included.


= Other stuff

Author::   Jim Weirich <jim@weirichhouse.org>
Requires:: Ruby 1.6.7 or later

== Warranty

This software is provided "as is" and without any express or
implied warranties, including, without limitation, the implied
warranties of merchantibility and fitness for a particular
purpose.
