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

Patrick J. Collins patrick at collinatorstudios.com
Mon Sep 26 17:11:28 EDT 2011


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



More information about the rspec-users mailing list