[rspec-users] sharing specs in a subclass
David Chelimsky
dchelimsky at gmail.com
Wed Jan 23 01:26:26 EST 2008
On Jan 23, 2008 12:04 AM, Scott Taylor <mailing_lists at railsnewbie.com> wrote:
>
> On Jan 23, 2008, at 12:02 AM, David Chelimsky wrote:
>
> > On Jan 22, 2008 10:49 PM, Jonathan Linowes
> > <jonathan at parkerhill.com> wrote:
> >> Hi
> >>
> >> I've spec'd a class and they pass.
> >>
> >> Now I'd like to assure that any subclass of this class also passes
> >> the same specs.
> >> Any suggestions for a clever way to handle this?
> >> I'd prefer to keep the existing specs as is (eg instead of moving
> >> everything into shared behaviors, or doing something to all the
> >> 'describe' lines)
> >
> > How about:
> >
> > [Subclass1, Subclass2, BaseClass].each do |klass|
> > describe klass do
> > ...
> > end
> > end
>
> That's sort of funny, being that I posted this solution on Courtney's
> blog yesterday.
I saw that. I've also done this before :)
> Is this what you actually use in this sort of situations? Are there
> other (better, or worse) alternatives?
I usually stick w/ shared example groups, but I sometimes use an
iterator like this. Not sure why. I'll think about it.
Cheers,
David
>
> 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