[rspec-users] alias method spec?

David Chelimsky dchelimsky at gmail.com
Mon Mar 19 18:48:09 EDT 2007


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
>


More information about the rspec-users mailing list