[rspec-users] alias method spec?

David Chelimsky dchelimsky at gmail.com
Tue Mar 20 17:49:01 EDT 2007


On 3/20/07, Bryan Helmkamp <bhelmkamp at gmail.com> wrote:
> On 3/20/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> > 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?
>
> I've experienced a similar situation before. The reason I looked at
> testing that they are the same method is that it seemed more DRY to do
> that than to copy/paste the specs for that method and replace the
> name. WDYT?

That makes sense. Another way to keep the code DRY would be to wrap
the example in a loop:

(pardon the trunk syntax....)

describe Thing do
  [:b, :c].each do |method|
    it "should do a when you send it #{method}" do
      #expect something....
      Thing.new.send method
    end
  end
end

This way the same behaviour get specified for both methods, but
there's only one set of specs describing the behaviour.

WDYT?



>
> -Bryan
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list