Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ruby

csv

rspec

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.

like image 978
Dave McNulla Avatar asked Jan 06 '12 07:01

Dave McNulla


1 Answers

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
    end
  end
end
like image 97
Steve Jorgensen Avatar answered Sep 21 '22 18:09

Steve Jorgensen