Class Test::Unit::Data::ClassMethods::Loader
In: lib/test/unit/data.rb
Parent: Object

Methods

load   load_csv   load_tsv   new  

Public Class methods

@api private

Public Instance methods

Load data from file.

@param [String] file_name full path to test data file.

  File format is automatically detected from filename extension.

@raise [ArgumentError] if file_name is not supported file format. @see load_csv @see load_tsv @api private

Load data from CSV file.

There are 2 types of CSV file as following examples. First, there is a header on first row and it‘s first column is "label". Another, there is no header in the file.

@example Load data from CSV file with header

  # test-data.csv:
  #  label,expected,target
  #  empty string,true,""
  #  plain string,false,hello
  #
  load_data("/path/to/test-data.csv")
  def test_empty?(data)
    assert_equal(data["expected"], data["target"].empty?)
  end

@example Load data from CSV file without header

  # test-data-without-header.csv:
  #  empty string,true,""
  #  plain string,false,hello
  #
  load_data("/path/to/test-data-without-header.csv")
  def test_empty?(data)
    expected, target = data
    assert_equal(expected, target.empty?)
  end

@api private

Load data from TSV file.

There are 2 types of TSV file as following examples. First, there is a header on first row and it‘s first column is "label". Another, there is no header in the file.

@example Load data from TSV file with header

  # test-data.tsv:
  #  label  expected target
  #  empty string   true      ""
  #  plain string   false     hello
  #
  load_data("/path/to/test-data.tsv")
  def test_empty?(data)
    assert_equal(data["expected"], data["target"].empty?)
  end

@example Load data from TSV file without header

  # test-data-without-header.tsv:
  #  empty string   true      ""
  #  plain string   false     hello
  #
  load_data("/path/to/test-data-without-header.tsv")
  def test_empty?(data)
    expected, target = data
    assert_equal(expected, target.empty?)
  end

@api private

[Validate]