Sha256: 928bb83e0516d5a1426ef6b69d0e7576371b7ff2d8a757a82d67b0ab773f18e1
Contents?: true
Size: 1.58 KB
Versions: 9
Compression:
Stored size: 1.58 KB
Contents
require_relative 'test_helper' class RecordReaderTest < Minitest::Test describe IOStreams::Record::Reader do let :file_name do File.join(File.dirname(__FILE__), 'files', 'test.csv') end let :json_file_name do File.join(File.dirname(__FILE__), 'files', 'test.json') end let :csv_rows do CSV.read(file_name) end let :expected do rows = csv_rows.dup header = rows.shift rows.collect { |row| header.zip(row).to_h } end describe '#each' do it 'csv file' do records = [] IOStreams::Record::Reader.file(file_name, cleanse_header: false) do |io| io.each { |row| records << row } end assert_equal expected, records end it 'json file' do records = [] IOStreams::Record::Reader.file(json_file_name, cleanse_header: false, format: :json) do |input| input.each { |row| records << row } end assert_equal expected, records end it 'stream' do rows = [] IOStreams::Line::Reader.file(file_name) do |file| IOStreams::Record::Reader.stream(file, cleanse_header: false) do |io| io.each { |row| rows << row } end end assert_equal expected, rows end end describe '#collect' do it 'json file' do records = IOStreams::Record::Reader.file(json_file_name, format: :json) do |input| input.collect { |record| record["state"] } end assert_equal expected.collect { |record| record["state"] }, records end end end end
Version data entries
9 entries across 9 versions & 1 rubygems