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.
2ce9c0106b5851b2294ba5eb9f5c04bd?d=identicon&s=25 Ashley Moran (Guest)
on 2008-10-16 22: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/
C694a032be7518a0d704318895f8fe1d?d=identicon&s=25 Ben Mabey (mabes)
on 2008-10-16 23:12
(Received via mailing list)
Ashley Moran 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
2ce9c0106b5851b2294ba5eb9f5c04bd?d=identicon&s=25 Ashley Moran (Guest)
on 2008-10-17 00:42
(Received via mailing list)
On Oct 16, 2008, at 10:02 pm, Ben Mabey 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/
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2008-10-19 05:31
(Received via mailing list)
Ben Mabey <ben@benmabey.com> 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
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2008-10-19 10:33
(Received via mailing list)
On 18 Oct 2008, at 14:53, Pat Maddox 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
2ce9c0106b5851b2294ba5eb9f5c04bd?d=identicon&s=25 Ashley Moran (Guest)
on 2008-10-19 22:19
(Received via mailing list)
On Oct 19, 2008, at 9:32 am, Matt Wynne 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/
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2008-10-20 09:06
(Received via mailing list)
On 19 Oct 2008, at 21:18, Ashley Moran wrote:

>
> On Oct 19, 2008, at 9:32 am, Matt Wynne 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
Afe1e6b75aace67db4b3ac064256b0f1?d=identicon&s=25 Rahoul Baruah (Guest)
on 2008-10-21 12:07
(Received via mailing list)
On 18 Oct 2008, at 14:53, Pat Maddox wrote:

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


Yay!  Thanks for the pointer Pat.

Baz.

Rahoul Baruah
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/
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2008-10-21 15:48
(Received via mailing list)
On Mon, Oct 20, 2008 at 2:03 AM, Matt Wynne <matt@mattwynne.net> 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
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2008-10-21 17: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?
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2008-10-21 18:02
(Received via mailing list)
On Tue, Oct 21, 2008 at 10:41 AM, Matt Wynne <matt@mattwynne.net> 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.