If I have a spec that needs to be run with different values to have it drive a real implementation and not a naive one. An example:
it "should return 'fizz' for multiples of three" do
@fizzbuzz.get_value(3).should == "fizz"
end
So far I haven't found any way to pass 3 in as a parameter. The spec below solves my problem but I'm wondering if it's the recommended way to do it or if there is any other, better way.
it "should return 'fizz' for multiples of three" do
[3, 6].each{|number| @fizzbuzz.get_value(number).should == "fizz" }
end
I don't like this because it uses loops, it's not readable and it only shows up as one spec when run, I would rather have it show up as two different tests.
#each
technique is very effective! I made a small DSL to make parameterized testing with RSpec a bit more convenient: github.com/odlp/rspec-with_params (it allows multiple parameters, and prints out each group with a "given a => b, x => y, " context for clarity) – Cullender