Dave McNulla Dave McNulla - 8 months ago 33
Ruby Question

Best way to organize tests in RSpec that have a Combinations of factor

I am creating some tests that have a variety of inputs. I am testing a purchasing website with new and returning user types, different products, promotion codes, payment options. I felt like this was a data-driven test set, probably calling for a csv or spreadsheet format of the test inputs.

I have been using rspec which was perfect for the last test set I created.

I would like to have consistent result formats. I am stuck on how to use data tables with RSpec. Has anybody used RSpec with a table of test inputs?

Thanks in advance for a direct solution or sound advice.


If you're going to use a table, I would define it in-line within the test file something like...

  %w( abc  123  def  ),
  %w( wxyz 9876 ab   ),
  %w( mn   10   pqrs )
].each do |a,b,c|
  describe "Given inputs #{a} and #{b}" do
    it "returns #{c}" do
      Something.whatever(a,b).should == c