Look up SharedExamplesGroups

http://rspec.info/rdoc/

On Thu, Mar 20, 2008 at 9:03 PM, Pietro Mascagni <[EMAIL PROTECTED]>
wrote:

> Is there anyway to achieve inheritance of specifications?
>
> Suppose I had an action like
>
> def index
>  filter = params[:filter] ? params[:filter] : '%'
>  order = params[:order] ? params[:order] : 'created_at DESC'
>  @posts = Post.find(:conditions => "title LIKE #{filter}", :order =>
> order)
>  ...
> end
>
> Now I might have half a dozen specs for this action that test it when
> neither :filter nor :order are supplied as params. But now what I
> would like to do is test it when one, other or both of the params are
> passed to the action. Most of the specs will probably not need to
> change, but I would still like to run them in the case where params
> are supplied, just to be sure there are no unwanted side effects.
> Probably only one or two of the specs need to be modified, for example
> to assert that only Posts matching the filter are returned.
>
> It seems to me that a nice way to do this would be if descriptions
> could be extended. So I could have a basic description of the action
>
> describe 'test index w/o params' do
>  ...
>  it 'should return the right posts'
> end
>
> and would then be able to extend it for each case, e.g.
>
> describe 'test index with filter param' do;
>  extends('test index w/o params')
>  ...
>  it 'should return the right posts' # overrides example in base spec
> end
>
> So this tests everything just like the base spec did, but
> changes/overrides one of the examples to correctly assert that the
> right posts are returned, thus giving me good confidence that the
> presence of the param does'nt cause breakage in places I might not
> normally bother to test because of my knowledge of the implementation.
>
> I can't find anything online to this effect. So far the best I have
> been able to do is write shared descriptions but this gets messy very
> quickly and causes all sorts of problems that I think makes it
> undesirable.
>
> Can anyone suggest a nice way for me to achieve the above.
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>



-- 
http://www.coreyhaines.com
The Internet's Premiere source of information about Corey Haines
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to