Mocks: expectations vs spying

Hi again

Ok, so I’m having a little research fling with JavaScript, and I’ve
uncovered something I hadn’t seen before: “spying”. Basically,
inspecting mocks after-the-fact, rather than setting expectations
upfront.

Here are the articles I found:

Does anyone know more about this technique, and its pros and cons vs
expectation-based mocking as used in RSpec mocks?

Thanks for any info
Ashley


http://www.patchspace.co.uk/

Ashley M. wrote:

AJAX Travelogue (Part 7): MockMe - My Not So Private Tech Life

Does anyone know more about this technique, and its pros and cons vs
expectation-based mocking as used in RSpec mocks?

Thanks for any info
Ashley

Pat has been working on adding the spy pattern to rspec and JoeSniff has
already added it to the rr mocking framework on github I believe. There
have been some recent posts on this mailing list about it. Searching
for spy in this groups past threads should give you some links to learn
more. HTH

-Ben

On Oct 16, 2008, at 10:02 pm, Ben M. wrote:

Pat has been working on adding the spy pattern to rspec and JoeSniff
has already added it to the rr mocking framework on github I
believe. There have been some recent posts on this mailing list
about it. Searching for spy in this groups past threads should give
you some links to learn more. HTH

Hi Ben

Ah, the original post about this was on my birthday, no wonder I
missed it :slight_smile:

Sorry for the I’m-too-damn-lazy-too-search-my-inbox post!

Ashley


http://www.patchspace.co.uk/

On 18 Oct 2008, at 14:53, Pat M. wrote:

more first (and hopefully others will too).

Pat

[1] http://notahat.com/not_a_mock

Looks sweet - it will be in my first mock on Monday!

cheers,
Matt

Ben M. [email protected] writes:

Pat has been working on adding the spy pattern to rspec

I quit once I found not_a_mock [1] which works nicely. My preference
would be to pull spies into RSpec eventually, but I want to use it a bit
more first (and hopefully others will too).

Pat

[1] http://notahat.com/not_a_mock

On 19 Oct 2008, at 21:18, Ashley M. wrote:

On Oct 19, 2008, at 9:32 am, Matt W. wrote:

[1] http://notahat.com/not_a_mock

Looks sweet - it will be in my first mock on Monday!

Thinking about it - how do you use multiple mocking frameworks in a
given project?

Is it safe to re-open a Spec::Runner.configure do |config| block at
the top of an individual spec after I’ve loaded spec_helper (which
will have to be configured to use the default rspec mocking that 90%
of the project uses)?

cheers,
Matt

On 18 Oct 2008, at 14:53, Pat M. wrote:

I quit once I found not_a_mock [1] which works nicely. My preference

Yay! Thanks for the pointer Pat.

Baz.

Rahoul B.
Web design and development: http://www.3hv.co.uk/
Nottingham Forest: http://www.eighteensixtyfive.co.uk/
Serious Rails Hosting: http://www.brightbox.co.uk/
Lifecast: http://www.madeofstone.net/

On Oct 19, 2008, at 9:32 am, Matt W. wrote:

[1] http://notahat.com/not_a_mock

Looks sweet - it will be in my first mock on Monday!

Wow, there’s some serious work gone into that, and I never knew it
existed! Searched my local archives (from March this year) for Pete
Yandell and he hasn’t posted once to promote it.

Gonna see if I can shoe-horn it into my Merb app somehow, now is the
best time to inflict maximum learning pain on myself :slight_smile:

Thanks for the link Pat.

Ashley


http://www.patchspace.co.uk/

So if I want to have a spec suite which uses a combination of mocking
frameworks, is this possible?

Maybe if some of the files include …/not_a_mock_spec_helper and the
others include …/default_spec_helper and then both those files
require some common spec_helper file?

On Mon, Oct 20, 2008 at 2:03 AM, Matt W. [email protected] wrote:

Thinking about it - how do you use multiple mocking frameworks in a given
project?

Is it safe to re-open a Spec::Runner.configure do |config| block at the top
of an individual spec after I’ve loaded spec_helper (which will have to be
configured to use the default rspec mocking that 90% of the project uses)?

Not really. The problem is that examples are stored for evaluation
later, whereas the configuration is evaluated right away.

The reason rspec won’t support using multiple mock frameworks is rspec
mocks and mocha both extend Object (to support mock behaviour on real
objects) and they use the same methods to create instances of mocks.

I think that if we wanted to support multiple mock frameworks, all of
the frameworks would have to offer an explicit mode where you could
extend objects to behave like mocks but would have to do so explicitly
for each object. Flexmock already works this way.

FWIW,
David

On Tue, Oct 21, 2008 at 10:41 AM, Matt W. [email protected] wrote:

So if I want to have a spec suite which uses a combination of mocking
frameworks, is this possible?

Maybe if some of the files include …/not_a_mock_spec_helper and the others
include …/default_spec_helper and then both those files require some common
spec_helper file?

That could work - but the conflict I described is a process-wide
conflict - so you’d need to run the examples in those dirs w/ separate
rake tasks to really eliminate the conflict.