Re: Library for Mocking
- From: Jim Weirich <jim@xxxxxxxxxxxxxxxx>
- Date: Tue, 21 Mar 2006 23:53:10 +0900
Thiago Arrais wrote:
On 3/20/06, Jim Weirich <jim@xxxxxxxxxxxxxxxx> 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/.
.
- References:
- Library for Mocking
- From: Thiago Arrais
- Re: Library for Mocking
- From: Jim Weirich
- Re: Library for Mocking
- From: Thiago Arrais
- Library for Mocking
- Prev by Date: Re: Welcome to our (ruby-talk ML) You are added automatically
- Next by Date: Disabling reception of copies of my own messages sent to ruby-talk
- Previous by thread: Re: Library for Mocking
- Next by thread: RubyForge Project Assistance
- Index(es):
Relevant Pages
|