[rspec-users] how to test identical behavior without being redundant?

Pat Maddox patmaddox at me.com
Mon Sep 26 17:39:03 EDT 2011


https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples


On Sep 26, 2011, at 2:11 PM, Patrick J. Collins wrote:

> I've got many models that have this declared:
>  has_many :notifications, :as => :notifiable, :dependent => :destroy 
> 
> 
> ...  And so I have many model specs such as:
> 
> describe Reply do
> 
>  it "should eliminate any associated notification records when destroyed" do
>    reply = create_reply
>    reply.notifications.should_not be_blank
> 
>    reply.destroy
>    reply.notifications.reload.should be_blank
>  end
> 
> end
> 
> describe Post do
> 
>  it "should eliminate any associated notification records when destroyed" do
>    post = create_post
>    post.notifications.should_not be_blank
> 
>    post.destroy
>    post.notifications.reload.should be_blank
>  end
> 
> end
> 
> etc...
> 
> Is there an ideal way to dynamically generate this for any models that respond
> to notificaions so that I don't have redundant noisy tests?
> 
> 
> Thanks.
> 
> Patrick J. Collins
> http://collinatorstudios.com
> 
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list