[rspec-users] alias method spec?

David Chelimsky dchelimsky at gmail.com
Tue Mar 20 05:49:02 EDT 2007


On 3/20/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:
>
> Well honestly I just wanted a method which could be called in the
> plural or singular, something like:
>
> column_name :a_col
>
> or
>
> columns_names :a_first_col, :a_second_col
>
> but I want it to be the same method, and I want it to work the same
> way.  (namely to return an array or a hash, and/or possibly set an
> instance variable)
>
> That's what led me to the idea in the first place, that I should test
> them in separate contexts, but assuring that they were indeed the
> same method in one of the contexts...

What benefit is there to knowing they are the same method, as long as
they both do the same thing?

>
> Scott
>
>
>
> On Mar 20, 2007, at 1:45 AM, s.ross wrote:
>
> > This is cool, but I just gotta ask: Is this kind of a spec about
> > behavior or low-level testing? I thought the whole zen of the spec
> > thing was to describe desired behaviors programmatically. The notion
> > being that these behaviors would be relatively coarse grained and the
> > finer-grained (i.e., implementation details) would sort themselves
> > out as you fix failures.
> >
> > The whole appeal to me is that you write the specs without suggesting
> > too much about the implementation of the solution. What you're
> > describing here appears to be tied intimately with the
> > implementation, so if you change that you break the spec, right?
> >
> > Just a thought :)
> >
> >
> > On Mar 19, 2007, at 8:55 PM, David Chelimsky wrote:
> >
> >> On 3/19/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:
> >>>
> >>> Wow.  Thanks.  You've opened up a whole new world of ruby for me.  I
> >>> had never heard of an UnboundMethod object before.
> >>
> >> Now the fun begins!!!!!
> >>
> >> Cheers,
> >> David
> >>
> >>>
> >>> I should have RTFM'ed before I was so quick on my reply.
> >>>
> >>> Thanks a bunch,
> >>>
> >>> Scott
> >>>
> >>>
> >>> On Mar 19, 2007, at 6:59 PM, David Chelimsky wrote:
> >>>
> >>>> 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
> >>>>>
> >>>> _______________________________________________
> >>>> 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
> >
> > _______________________________________________
> > 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