Sha256: 52c2f2119a737c08496c61ec2f7b061281ee5aa1acafcf06b9df7f8de1089d2b
Contents?: true
Size: 1.59 KB
Versions: 4
Compression:
Stored size: 1.59 KB
Contents
require 'spec_helper' describe Csv2hash::Parser::Collection do let(:definition) do Csv2hash::Definition.new [ { position: 0, key: 'name' } ], Csv2hash::Definition::COLLECTION end let(:data_source) { [ [ 'John Doe' ], [ 'Jane Doe' ] ] } subject do Csv2hash.new(definition, 'file_path', false, data_source) end context 'regular way' do it { expect { subject.parse }.to_not raise_error } it { subject.tap do |parser| parser.parse end.data.should eql({ data: [ { 'name' => 'John Doe' }, { 'name' => 'Jane Doe' } ] }) } context 'with header' do before { subject.definition.header_size = 1 } let(:data_source) { [ [ 'Name' ], [ 'John Doe' ], [ 'Jane Doe' ] ] } it { subject.tap { |c| c.parse }.data.should eql({ data: [ { 'name' => 'John Doe' }, { 'name' => 'Jane Doe' } ] }) } end end context 'with nested' do let(:data_source) { [ [ 'John Doe', 22 ], [ 'Jane Doe', 19 ] ] } before do definition.rules << { position: 1, key: 'age', nested: 'infos' } end it { subject.tap { |c| c.parse }.data.should eql( { data: [ { 'name' => 'John Doe', 'infos' => { 'age' => 22 } }, { 'name' => 'Jane Doe', 'infos' => { 'age' => 19 } } ] } ) } end context '#ignore_blank_line' do let(:data_source) { [ [ 'John Doe' ], [ 'Jane Doe' ], [ nil ] ] } it { subject.tap do |parser| parser.ignore_blank_line = true parser.parse end.data.should eql({ data: [ { 'name' => 'John Doe' }, { 'name' => 'Jane Doe' } ] }) } end end
Version data entries
4 entries across 4 versions & 1 rubygems