Class: Test::Unit::Data::ClassMethods::CSVDataLoader
- Inherits:
-
Object
- Object
- Test::Unit::Data::ClassMethods::CSVDataLoader
- Defined in:
- lib/test/unit/data.rb
Instance Method Summary (collapse)
-
- (CSVDataLoader) initialize(test_case)
constructor
A new instance of CSVDataLoader.
- - (Object) load(file_name)
Constructor Details
- (CSVDataLoader) initialize(test_case)
A new instance of CSVDataLoader
41 42 43 |
# File 'lib/test/unit/data.rb', line 41 def initialize(test_case) @test_case = test_case end |
Instance Method Details
- (Object) load(file_name)
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/test/unit/data.rb', line 45 def load(file_name) require 'csv' header = nil CSV.foreach(file_name) do |row| if header.nil? header = row next end label = nil data = {} header.each_with_index do |key, i| if key == "label" label = row[i] else data[key] = normalize_value(row[i]) end end @test_case.data(label, data) end end |