Sha256: 0ffd0d35626ab3d7fb7fa1d50c78c6069128dc9407c61717fe9e1680df457425

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

require File.dirname(__FILE__) + '/spec_helper.rb'

include CsvMapper

describe CsvMapper do
    
  before(:each) do    
    @mapped_klass = Class.new { include CsvMapper }
    @mapped = @mapped_klass.new
  end

  it "should allow the creation of CSV mappings" do
    mapping = @mapped.map_csv do
      start_at_row 2      
    end
    
    mapping.should be_instance_of(CsvMapper::RowMap)
    mapping.start_at_row.should == 2
  end
  
  it "should import a CSV IO" do
    io = 'foo,bar,00,01'
    results = @mapped.import(io, :type => :io) do 
      first
      second
    end
    
    results.should be_kind_of(Enumerable)
    results.should have(1).things
    results[0].first.should == 'foo'
    results[0].second.should == 'bar'
  end
  
  it "should import a CSV File IO" do
    results = import(File.dirname(__FILE__) + '/test.csv') do
      start_at_row 1
      [first_name, last_name, age]
    end
    
    results.size.should == 3
  end 
  
  it "should stop importing at a specified row" do
    results = import(File.dirname(__FILE__) + '/test.csv') do
      start_at_row 1
      stop_at_row 2
      [first_name, last_name, age]
    end

    results.size.should == 2
  end
  
  it "should import non-comma delimited files" do
    piped_io = 'foo|bar|00|01'
    
    results = import(piped_io, :type => :io) do
      delimited_by '|'
      [first, second]
    end
    
    results.should have(1).things
    results[0].first.should == 'foo'
    results[0].second.should == 'bar'
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csv-mapper-0.0.3 spec/csv-mapper_spec.rb