spec/csv2hash/parser_spec.rb in csv2hash-0.7.2 vs spec/csv2hash/parser_spec.rb in csv2hash-0.7.3

- old
+ new

@@ -1,3 +1,39 @@ require 'spec_helper' -describe Csv2hash::Parser +module Csv2hash + describe Parser do + let(:definition) do + Main.generate_definition :foo do + set_type { Definition::COLLECTION } + mapping { cell position: 0, key: 'name' } + end + end + + let(:john) { ' John Doe ' } + let(:jane) { ' Jane Doe ' } + let(:data_source) { [ [ john ], [ jane ] ] } + let(:ignore_blank_line) { false } + + subject do + Main.new(definition, data_source, ignore_blank_line: ignore_blank_line, sanitizer: sanitizer) + end + + context 'regular way' do + let(:sanitizer) { false } + it { + expect(subject.tap do |parser| + parser.parse! + end.data).to eql({ data: [ { 'name' => john }, { 'name' => jane } ] }) + } + end + + context 'sanitizer way' do + let(:sanitizer) { true } + it { + expect(subject.tap do |parser| + parser.parse! + end.data).to eql({ data: [ { 'name' => 'John Doe' }, { 'name' => 'Jane Doe' } ] }) + } + end + end +end