Is it possible to have parameterized specs in RSpec? Is it possible to have parameterized specs in RSpec? ruby ruby

Is it possible to have parameterized specs in RSpec?


To generate separate tests you could do:

[3, 6].each do |num|  it "should return 'fizz' for multiples of three (#{num})" do      @fizzbuzz.get_value(num).should == "fizz"  endend

Because spec files are simple run as ruby scripts you can use all the standard ruby constructs to generate tests on the fly.

Even better you can use Numeric#step to easily generate a certain range of tests, e.g. for [3, 6, 9, 12, 15, 18]:

3.step(18, 3) do |num|  it "should return 'fizz' for multiples of three (#{num})" do      @fizzbuzz.get_value(num).should == "fizz"  endend