Forum: Ruby Aliasing vs Delegation

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.
Thomas S. (Guest)
on 2008-10-24 22:04
(Received via mailing list)
Which would you recommend for the implementation of a stub/mock lib?

Thanks,
trans.
Thomas S. (Guest)
on 2008-10-25 02:01
(Received via mailing list)
On Oct 24, 2:04 pm, Trans <removed_email_address@domain.invalid> wrote:
> Which would you recommend for the implementation of a stub/mock lib?

An update to this question: In considering it most of the day, I've
decided aliasing is a poor approach. The reason is singleton methods.
Though singleton methods may be rare, their use by the SUT could end
up clobbering stub methods.

As an alternate to aliasing, singleton methods could be used to define
stub methods. While they suffer the same potential problem, it is not
an issue if good practices are used by the SUT, ie. extend objects
with modules rather than defining singleton methods directly.

So I guess the question has changed. It is now:

  Singleton Methods or Delegation?

Related to this, one question I have about best practices of using
stubs/mocks... Is it considered bad practice to stub/mock an internal
SUT object? In other words, should stub/mocks always be temporary
objects that are dropped into the SUT interfaces?  (I hope that's
clear enough.)

Thanks,
T.
This topic is locked and can not be replied to.