Thiago Arrais wrote:
> On 3/20/06, Jim Weirich <jim / weirichhouse.org> wrote:
>> Actually, you still need to specify the behavior of the mock.  The "use"
>> module method just ensures that that mock_verify is properly called at
>> the end of the test.
> 
> Hmm... I knew I was wrong at some point. I think I got fooled by the
> docs at http://onestepback.org/software/flexmock/
> 
> Somewhere in the simple example, you can read
> 
> FlexMock.use("temp") do |sensor|
>     sensor = FlexMock.new
>     sensor.should_receive(:read_temperature).and_return { readings.shift 
> }
> sampler = TemperatureSampler.new(sensor)
> assert_equal 12, sampler.average_temp
> 
> Because of indentation it seems that the "should_receive" methods
> (i.e. the setup phase) go inside the block that gets passed to the use
> method and the stimuling calls go outside. 

Gah!  That example is all messed up.  It looks like I might have been 
interupted while editting it and never got back to cleaning it up.  I 
will fix this ASAP.

Sorry for the confusion.  Its not a good thing when your first example 
is garbled.

> At least in my original example it is. However, I see that we may
> often need to specify that order is not important, specially when we
> use the repetition modifiers (like once and twice). [...]

Ordering issues was one of the driving forces that lead to the creation 
of FlexMock.  At the time, the mocking framework I was using was too 
inflexible on the allowed order of received messages.  Requiring the 
exact order was, in my mind, an overspecification of the behavior I 
wished to implement.  I'm pretty happy with the ordering specification 
in FlexMock at the moment.

One of the advantages of a recording mode for mocks is that you can give 
the recorder to a known good algorithm and record the actual calls as 
expectations.    Then give the mock to a reimplemenation of the known 
good algorithm and can check that the new algorithm exactly matches the 
old.  Obviously, this only works for imperative interfaces (ie. no 
queries, because the recorder wont return the proper values).  But for 
that limited range of use, it is pretty handy.

--
-- Jim Weirich

-- 
Posted via http://www.ruby-forum.com/.