[rspec-users] Sufficiently tested?
U. M.
lists at ruby-forum.com
Fri Mar 9 13:06:16 UTC 2012
Hi everybody,
I have a general question about how many different cases have to be
covered in one Example.
Considering the famous Fizzbuzz program, you should test if your output
is either "Fizz", "buzz", "Fizzbuzz" or just the number (between 1 and
100). Pretty simple. However, I often see solutions of testing multiples
of 3 only by looking at some relevant values like 6, 9 etc.
it "should return 'fizz' when number is divisible by 3" do
@fizzbuzz.calculate(3).should == 'fizz'
@fizzbuzz.calculate(6).should == 'fizz'
@fizzbuzz.calculate(9).should == 'fizz'
end
So far, so good. But what if I claim that the test will fail in case of
12? It's actually not covered and we are just assuming, that all further
multiples will work as well, because these do. My idea was to check all
multiples right away in a loop.
it "should return Fizz if number is divisible only by 3" do
(1..100).each do |number|
@fizzbuzz.calculate(number).should == "Fizz" if number % 3 == 0 &&
number % 5 != 0
end
end
Given that the calculate method works fine, both ways will pass. But my
question is: Does my solution more than it actually needs to or is the
first one in fact a little too lazy?
Thanks for your thoughts.
Ulfmann
--
Posted via http://www.ruby-forum.com/.
More information about the rspec-users
mailing list