[rspec-users] alias method spec?

David Chelimsky dchelimsky at gmail.com
Mon Mar 19 18:59:47 EDT 2007


On 3/19/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:
>
>
> But that doesn't check that the methods are the same, does it?
> Doesn't it only check if the values returned by the methods are equal
> (in this case, nil)?

That's not what I get from the docs:

http://www.ruby-doc.org/core/classes/Module.html#M001682

Seems to me it's an UnboundMethod object (or Method in the second
example I gave).

WDYT?


>
> Scott
>
>
> On Mar 19, 2007, at 6:48 PM, David Chelimsky wrote:
>
> > On 3/19/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:
> >>
> >> I am completely baffled by this one - My guess is that there is no
> >> pure ruby way to do this - but how could I set up a spec to test that
> >> one method is an alias of another?
> >
> > class Foo
> >   def bar
> >   end
> >   alias :baz :bar
> > end
> >
> > context "Foo class" do
> >   specify "should use the same method for #baz as #bar" do
> >     Foo.instance_method(:baz).should == Foo.instance_method(:bar)
> >   end
> > end
> >
> > context "Foo instance" do
> >   specify "should use the same method for #baz as #bar" do
> >     foo = Foo.new
> >     foo.method(:baz).should == foo.method(:bar)
> >   end
> > end
> >
> > equal? won't work because the resulting method isn't the same object,
> > but you'll see that == fails when the implementations they point to
> > are different.
> >
> > Hope that works for you.
> >
> > David
> >
> >>
> >> Thanks for any help,
> >>
> >> Scott
> >>
> >> _______________________________________________
> >> rspec-users mailing list
> >> rspec-users at rubyforge.org
> >> http://rubyforge.org/mailman/listinfo/rspec-users
> >>
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list