Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec: test number of rows in CSV output

In Rspec how do I test the number of rows that are in a CSV file?

I have created a CSV file in a mutation. I am able to test the output of the CSV by checking if certain text is included. However, I would like to be able to test the number of rows that are in the output.

Please find an example of what I have tested so far below which passes:

describe "#execute" do

    it "creates a CSV for the specified content" do
      outcome = mutation.run(mutation_params)

      expect(outcome.result).to include("Name")
    end
  end
like image 235
atw Avatar asked Jun 14 '16 14:06

atw


1 Answers

You could just count the newline seperators:

expect(outcome.result.split("\n").size).to eq(10)
like image 66
miscreant Avatar answered Sep 21 '22 02:09

miscreant