Sha256: 38f23e4c5809fd52af1dbcd40d5dd9ef10be9ce5eef63069ece81222d5086b2b

Contents?: true

Size: 892 Bytes

Versions: 1

Compression:

Stored size: 892 Bytes

Contents

require 'spec_helper'

describe Csv2hash::Parser::Mapping do

  let(:definition) do
    Csv2hash::Definition.new [ { position: [0,0], key: 'name' } ], Csv2hash::Definition::MAPPING
  end

  let(:data_source) { [ [ 'John Doe' ] ] }

  subject do
    Csv2hash::Main.new(definition, data_source, ignore_blank_line: false)
  end

  context 'regular way' do
    it { expect { subject.parse }.to_not raise_error }
    it {
      expect(subject.tap do |csv2hash|
        csv2hash.parse
      end.data).to eql({ data: [ { 'name' => 'John Doe' } ] })
    }
  end

  context 'with nested' do
    let(:data_source) { [ [ 'John Doe', 22 ] ] }
    before do
      definition.rules << { position: [0,1], key: 'age', nested: 'infos' }
    end
    it {
      expect(subject.tap { |c| c.parse }.data).to eql(
        { data: [ { 'name' => 'John Doe', 'infos' => { 'age' => 22 } } ] }
      )
    }
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csv2hash-0.5.0 spec/csv2hash/parser/mapping_spec.rb