Simple vs. DRY Rails Specs
I’m toying with two different styles of Rails Specification (RSpec) testing. One is easier to read, the other is much more DRY (do not repeat yourself). Which do you think is better?
DRY:specify "has many ContentTerms" do
content_term_ids = [ 1, 2, 3 ]
@content.content_terms.should have(content_term_ids.size).records
for id in content_term_ids
@content.content_terms.should include(ContentTerm.find(id))
end
endspecify "has many ContentTerms" do
@content.content_terms.should have(3).records
@content.content_terms.should include(ContentTerm.find(1))
@content.content_terms.should include(ContentTerm.find(2))
@content.content_terms.should include(ContentTerm.find(3))
endThe DRY version makes me feel special but the simpler version is much easier on my brain. I think I’ll go with the simple one… for now.