John Cheng
John Cheng

Reputation: 1

Ruby on Rails - Testing the contents of a CSV file

So I have a link on my rails web page that generates a CSV file. How would I go about writing a functional test to test that the CSV file is created properly and check the contents of it?

Upvotes: 0

Views: 655

Answers (1)

Jesse Wolgamott
Jesse Wolgamott

Reputation: 40277

There are probably many ways. Here's a version that won't make you jump through browser hoops

  1. Extract the creation of a CSV to another non-controller class
  2. In your controller test, assert your CreatesCSV receives the right parameters
  3. Test your CreatesCSV class by writing its output to a file, then reading it in and verifying the hash is correct.

Upvotes: 1

Related Questions