mardi 19 avril 2016

how do you test csv file content in Rails?

I'm writing a simple CanadaPost price shipping API, where the prices are given in a PDF document in table format (see page 3 of http://ift.tt/1Spwcrj). The data is extracted into csv files and imported into the database (table prices has columns weight, rate_code and date). The model and controller are very simple: they take a weight, rate_code and date and query the prices table.

I'm trying to create a suite of tests which tests the existence and correctness of every single price in that chart. It has to be generic and reusable because the data changes every year. I thought of some ideas: 1) Read the same csv files that were used to import the data into the database and create a single RSpec example that loops around all rows and columns and tests the returned price. 2) Convert the csv files into fixtures for the prices controller and test each fixture.

I'm also having a hard time categorizing these tests. They are not unit tests, but are they really functional/feature tests? They sound more like integration tests, but I'm not sure if Rails differentiates functional tests from integration tests. Maybe the answer is obvious and I'm not seeing it.

TIA,
J

Aucun commentaire:

Enregistrer un commentaire