Forum: RSpec Passing self to matchers

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.
F85bacbbd4814799d4526b3e35a431df?d=identicon&s=25 Brandon Olivares (Guest)
on 2009-04-13 09:24
(Received via mailing list)
Hi,

I've noticed in several matchers that the matcher method passes self to
the
constructor of the class. Then that's used to call several of the
methods
used. For instance, in RouteFor, self is passed, and it is used to call
assert_recognizes.

I'm just curious why this is, and when this is required.

Brandon
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-04-13 12:41
(Received via mailing list)
On Mon, Apr 13, 2009 at 4:19 AM, Brandon Olivares
<programmer2188@gmail.com> wrote:
> Hi,
>
> I've noticed in several matchers that the matcher method passes self to the
> constructor of the class. Then that's used to call several of the methods
> used. For instance, in RouteFor, self is passed, and it is used to call
> assert_recognizes.
>
> I'm just curious why this is, and when this is required.

Because assert_recognizes is defined in the context of the example,
not inside the scope of the matcher. This is only necessary in such
cases that helper methods are outside the matcher itself.

HTH,
David
This topic is locked and can not be replied to.