I'm pretty new to TDD. Is there a standard approach on this: Is it
better to write individual tests, or combine them? A specific example
- if a model Foo validates the presence of both bar and baz, is it
better to have a test each for bar and for baz, or to combine the
validations into a combined bar/baz test?
I'm pretty new to TDD. Is there a standard approach on this: Is it
better to write individual tests, or combine them? A specific example
- if a model Foo validates the presence of both bar and baz, is it
better to have a test each for bar and for baz, or to combine the
validations into a combined bar/baz test?
I'd test them individually. In general, you want each test pretty
atomic.
So for example, take a look at
(the validation specs start at line 217). I've got separate specs for
each validation.
That code could use some DRYing up, though, and I do sometimes do things
like
['one', 'two', 'three'].each do |field|
it "should require #{field}" do
@model.send "#{field}=", nil
@model.should_not be_valid
end
end
but note that this still produces three separate specs. I'd feel wrong
if it didn't.
I'm pretty new to TDD. Is there a standard approach on this: Is it
better to write individual tests, or combine them? A specific example
- if a model Foo validates the presence of both bar and baz, is it
better to have a test each for bar and for baz, or to combine the
validations into a combined bar/baz test?
I'd test them individually. In general, you want each test pretty
atomic.