Sha256: 6eb123f7dfb5a60cda9c3db61d88bfdc789b2febf72f757df110f6f876dfc272

Contents?: true

Size: 1.77 KB

Versions: 10

Compression:

Stored size: 1.77 KB

Contents

require 'spec_helper'

describe Roo::CSV do
  let(:path) { 'test/files/csvtypes.csv' }
  let(:csv) { Roo::CSV.new(path) }

  describe '.new' do
    it 'creates an instance' do
      expect(csv).to be_a(Roo::CSV)
    end
  end

  describe '.new with stream' do
    let(:csv) { Roo::CSV.new(File.read(path)) }
    it 'creates an instance' do
      expect(csv).to be_a(Roo::CSV)
    end
  end

  describe '#parse' do
    subject do
      csv.parse(options)
    end
    context 'with headers: true' do
      let(:options) { { headers: true } }

      it "doesn't blow up" do
        expect { subject }.to_not raise_error
      end
    end
  end

  describe '#parse_with_clean_option' do
    subject do
      csv.parse(options)
    end
    context 'with clean: true' do
      let(:options) { {clean: true} }
      let(:path) { 'test/files/parse_with_clean_option.csv' }

      it "doesn't blow up" do
        expect { subject }.to_not raise_error
      end
    end
  end

  describe '#csv_options' do
    context 'when created with the csv_options option' do
      let(:options) do
        {
          col_sep: '\t',
          quote_char: "'"
        }
      end

      it 'returns the csv options' do
        csv = Roo::CSV.new(path, csv_options: options)
        expect(csv.csv_options).to eq(options)
      end
    end

    context 'when created without the csv_options option' do
      it 'returns a hash' do
        csv = Roo::CSV.new(path)
        expect(csv.csv_options).to eq({})
      end
    end
  end

  describe '#set_value' do
    it 'returns the cell value' do
      expect(csv.set_value('A', 1, 'some-value', nil)).to eq('some-value')
    end
  end

  describe '#set_type' do
    it 'returns the cell type' do
      expect(csv.set_type('A', 1, 'some-type', nil)).to eq('some-type')
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
roo-2.10.1 spec/lib/roo/csv_spec.rb
roo-2.10.0 spec/lib/roo/csv_spec.rb
roo-2.9.0 spec/lib/roo/csv_spec.rb
roo-2.8.3 spec/lib/roo/csv_spec.rb
roo-2.8.2 spec/lib/roo/csv_spec.rb
roo-2.8.1 spec/lib/roo/csv_spec.rb
roo-2.8.0 spec/lib/roo/csv_spec.rb
roo-2.7.1 spec/lib/roo/csv_spec.rb
roo-2.7.0 spec/lib/roo/csv_spec.rb
roo-2.6.0 spec/lib/roo/csv_spec.rb