Re: Library for Mocking



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


.



Relevant Pages

  • Thanks for the responces.. another question
    ... I see it uses either Rijndael, Twofish, ... or Blowfish. ... Any algorithm better than the other? ... Also what is a proper ...
    (sci.crypt)
  • Re: Surrogate factoring, corrected algorithm
    ... Tim Peters wrote: ... I get a mere 24960 gcd trials. ... > some j, so at least one of {proof, algorithm, implementation} is wrong. ... I never saw a proof of the claim that one of the GCD's must be a proper ...
    (sci.math)
  • Re: Surrogate factoring, corrected algorithm
    ... Tim Peters wrote: ... I get a mere 24960 gcd trials. ... > some j, so at least one of {proof, algorithm, implementation} is wrong. ... I never saw a proof of the claim that one of the GCD's must be a proper ...
    (sci.crypt)
  • Re: Tips for 744T?
    ... "I would love to hear any tips or troubleshooting advice regarding ... I am being asked to pick up and use one before I have proper ... Be careful erasing files from a previous job on a recorder you don't ...
    (rec.arts.movies.production.sound)
  • Re: Writing spaghetti code for obfuscation/encryption
    ... > In any case, cryptographic security is NOT achieved by hiding the algorithm, but ... > by proper use of a proven, tested strong algorithm and CORRECT KEY MANAGEMENT, the latter ...
    (comp.lang.asm.x86)