Sha256: 15118e69c98d8b04a9b7490a1441334eb67cc61df45196911deddbd9c5ec9bf6

Contents?: true

Size: 1.98 KB

Versions: 16

Compression:

Stored size: 1.98 KB

Contents

require 'spec_helper'

fixture_path = 'spec/fixtures'

describe 'test exceptions for invalid headers' do
  it 'raises error on duplicate headers' do
    expect {
      SmarterCSV.process("#{fixture_path}/duplicate_headers.csv", {})
    }.to raise_exception(SmarterCSV::DuplicateHeaders)
  end

  it 'raises error on duplicate given headers' do
    expect {
      options = {:user_provided_headers => [:a,:b,:c,:d,:a]}
      SmarterCSV.process("#{fixture_path}/duplicate_headers.csv", options)
    }.to raise_exception(SmarterCSV::DuplicateHeaders)
  end

  it 'raises error on duplicate mapped headers' do
    expect {
      # the mapping is right, but the underlying csv file is bad
      options = {:key_mapping => {:email => :a, :firstname => :b, :lastname => :c, :manager_email => :d, :age => :e} }
      SmarterCSV.process("#{fixture_path}/duplicate_headers.csv", options)
    }.to raise_exception(SmarterCSV::DuplicateHeaders)
  end


  it 'does not raise an error if no required headers are given' do
    options = {:required_headers => nil} # order does not matter
    data = SmarterCSV.process("#{fixture_path}/user_import.csv", options)
    data.size.should eq 2
  end

  it 'does not raise an error if no required headers are given' do
    options = {:required_headers => []} # order does not matter
    data = SmarterCSV.process("#{fixture_path}/user_import.csv", options)
    data.size.should eq 2
  end

  it 'does not raise an error if the required headers are present' do
    options = {:required_headers => [:lastname,:email,:firstname,:manager_email]} # order does not matter
    data = SmarterCSV.process("#{fixture_path}/user_import.csv", options)
    data.size.should eq 2
  end

  it 'raises an error if a required header is missing' do
    expect {
      options = {:required_headers => [:lastname,:email,:employee_id,:firstname,:manager_email]} # order does not matter
      SmarterCSV.process("#{fixture_path}/user_import.csv", options)
    }.to raise_exception(SmarterCSV::MissingHeaders)
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
smarter_csv-1.5.0 spec/smarter_csv/invalid_headers_spec.rb
smarter_csv-1.4.2 spec/smarter_csv/invalid_headers_spec.rb
smarter_csv-1.4.0 spec/smarter_csv/invalid_headers_spec.rb
smarter_csv-1.3.0 spec/smarter_csv/invalid_headers_spec.rb
smarter_csv-1.2.8 spec/smarter_csv/invalid_headers_spec.rb
smarter_csv-1.2.7 spec/smarter_csv/invalid_headers_spec.rb
pokedex-terminal-0.2.8 vendor/bundle/ruby/2.7.0/gems/smarter_csv-1.2.6/spec/smarter_csv/invalid_headers_spec.rb
pokedex-terminal-0.2.7 vendor/bundle/ruby/2.7.0/gems/smarter_csv-1.2.6/spec/smarter_csv/invalid_headers_spec.rb
pokedex-terminal-0.2.6 vendor/bundle/ruby/2.7.0/gems/smarter_csv-1.2.6/spec/smarter_csv/invalid_headers_spec.rb
pokedex-terminal-0.2.5 vendor/bundle/ruby/2.7.0/gems/smarter_csv-1.2.6/spec/smarter_csv/invalid_headers_spec.rb
pokedex-terminal-0.2.4 vendor/bundle/ruby/2.7.0/gems/smarter_csv-1.2.6/spec/smarter_csv/invalid_headers_spec.rb
smarter_csv-1.2.6 spec/smarter_csv/invalid_headers_spec.rb
smarter_csv-1.2.5 spec/smarter_csv/invalid_headers_spec.rb
smarter_csv-1.2.4 spec/smarter_csv/invalid_headers_spec.rb
smarter_csv-1.2.3 spec/smarter_csv/invalid_headers_spec.rb
smarter_csv-1.2.0 spec/smarter_csv/invalid_headers_spec.rb