Sha256: 2984b66772ce5caef3e2a00efc38dc1018c443868df0069444e7b187597f05a9

Contents?: true

Size: 1.52 KB

Versions: 6

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'

describe Topographer::Importer::Mapper::DefaultFieldMapping do
  let(:static_mapping) do
    Topographer::Importer::Mapper::DefaultFieldMapping.new('field1') do
      10+5
    end
  end
  let(:failed_static_mapping) do
    Topographer::Importer::Mapper::DefaultFieldMapping.new('field1') do
      raise 'FAILURE'
    end
  end

  let(:result) { Topographer::Importer::Mapper::Result.new('test') }
  let(:result2) { Topographer::Importer::Mapper::Result.new('test') }
  describe '#initialize' do
    it 'should not create a static mapping without a behavior block' do
      expect { Topographer::Importer::Mapper::DefaultFieldMapping.new('broken mapping') }.
          to raise_error(Topographer::InvalidMappingError)
    end
  end
  describe '#process_input' do
    it 'should return the result of the behavior block' do
      static_mapping.process_input({}, result)
      expect(result.errors?).to be_false
      expect(result.data['field1']).to be 15
    end
    it 'should record any exceptions that occur within the block as errors' do
      failed_static_mapping.process_input({}, result)
      expect(result.errors?).to be_true
      expect(result.errors.values).to include('FAILURE')
    end
    it 'should not rescue Exceptions that do not inherit from standard error' do
      mapper = Topographer::Importer::Mapper::DefaultFieldMapping.new('output_column') do
        raise Exception, 'Field1 MUST BE 4'
      end
      expect{ mapper.process_input({'field1' => false}, result) }.to raise_error(Exception)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
topographer-0.0.7 spec/topographer/importer/mapper/default_field_mapping_spec.rb
topographer-0.0.6 spec/topographer/importer/mapper/default_field_mapping_spec.rb
topographer-0.0.5 spec/topographer/importer/mapper/default_field_mapping_spec.rb
topographer-0.0.4 spec/topographer/importer/mapper/default_field_mapping_spec.rb
topographer-0.0.3 spec/Topographer/importer/mapper/default_field_mapping_spec.rb
topographer-0.0.2 spec/Cartographer/importer/mapper/default_field_mapping_spec.rb