Class: Test::Unit::Data::ClassMethods::CSVDataLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/test/unit/data.rb

Instance Method Summary collapse

Constructor Details

#initialize(test_case) ⇒ CSVDataLoader



41
42
43
# File 'lib/test/unit/data.rb', line 41

def initialize(test_case)
  @test_case = test_case
end

Instance Method Details

#load(file_name) ⇒ Object



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