How to make unit test of csv file on Ruby on Rails

In test/unit/sample_test.rb:

# coding: utf-8
require 'test_helper'
require 'csv'
class Sample < ActionController::TestCase

#============================== CSV TEST ====================================
test "csv file" do
  get :approval, format: :csv
  assert_response :success
  assert_equal "text/csv; charset=shift_jis", response.content_type
  # ===================checking valid value in csv file============================
  #csv = CSV.parse response.body # Let raise if invalid CSV
  csv = CSV.read("test/unit/sample_data.csv", "r:ISO-8859-1")
  assert csv
  assert_equal(csv.last[29], "Facebook1", "PROVIDER NAME DOESN`T MATCH!")
end
#============================== CSV TEST ====================================


 Decription:
The line "  
assert_equal(csv.last[29], "Facebook1", "PROVIDER NAME DOESN`T MATCH!")"
checks the 29th element of last row of csv file, that equals to "Facebook1" or not.
If not displays the error message "PROVIDER NAME DOESN`T MATCH!".

Comments