spec/csv2hash/parser/collection_spec.rb in csv2hash-0.0.2 vs spec/csv2hash/parser/collection_spec.rb in csv2hash-0.1

- old
+ new

@@ -1,31 +1,29 @@ require 'spec_helper' -describe Parser::Collection do +describe Csv2hash::Parser::Collection do let(:definition) do - Definition.new [ { position: 0, key: 'name' } ], Definition::COLLECTION + 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').tap do |csv2hash| - csv2hash.data_source = data_source - end + 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 |csv2hash| - csv2hash.parse + 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' ] ]} + 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 @@ -44,6 +42,15 @@ } ) } 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 \ No newline at end of file