Forum: RSpec Mocks: expectations vs spying

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ashley M. (Guest)
on 2008-10-17 00:54
(Received via mailing list)
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:
http://ajaxian.com/archives/mockme-a-new-javascrip...
http://blog.johanneslink.net/2008/08/08/ajax-trave...
http://blog.johanneslink.net/2008/08/09/ajax-trave...

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/
http://aviewfromafar.net/
Ben M. (Guest)
on 2008-10-17 01:12
(Received via mailing list)
Ashley M. wrote:
>
> http://blog.johanneslink.net/2008/08/09/ajax-trave...
>
> 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
Ashley M. (Guest)
on 2008-10-17 02:42
(Received via mailing list)
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 :)

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

Ashley

--
http://www.patchspace.co.uk/
http://aviewfromafar.net/
Pat M. (Guest)
on 2008-10-19 07:31
(Received via mailing list)
Ben M. <removed_email_address@domain.invalid> 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
Matt W. (Guest)
on 2008-10-19 12:33
(Received via mailing list)
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
Ashley M. (Guest)
on 2008-10-20 00:19
(Received via mailing list)
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 :)

Thanks for the link Pat.

Ashley

--
http://www.patchspace.co.uk/
http://aviewfromafar.net/
Matt W. (Guest)
on 2008-10-20 11:06
(Received via mailing list)
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
Rahoul B. (Guest)
on 2008-10-21 14:07
(Received via mailing list)
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/
David C. (Guest)
on 2008-10-21 17:48
(Received via mailing list)
On Mon, Oct 20, 2008 at 2:03 AM, Matt W. <removed_email_address@domain.invalid> 
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
Matt W. (Guest)
on 2008-10-21 19:43
(Received via mailing list)
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?
David C. (Guest)
on 2008-10-21 20:02
(Received via mailing list)
On Tue, Oct 21, 2008 at 10:41 AM, Matt W. <removed_email_address@domain.invalid> 
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.
This topic is locked and can not be replied to.