Sha256: 8bd58f7c4182f02c6c9a70055342187602a1085b51fcc324b9c869c93ec099f9

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

require 'spec_helper'
require 'sepparator/spreadsheet_converter'
require 'tempfile'
require 'fileutils'

describe Sepparator::SpreadsheetConverter do

  it 'remembers the column separator' do
    sep = 'foobar'
    expect(described_class.new(col_sep: sep).col_sep).to eq(sep)
  end

  context '#convert' do
    #let(:xls_path) { Tempfile.new('convert-to-xlsx')}
    let(:xls_path) { '/tmp/example.xlsx' }
    let(:csv_path) { File.join(__dir__, 'example.csv')}
    subject { described_class.new.convert(csv_path, xls_path)}

    before do
      FileUtils.rm_f xls_path
    end

    it 'converts a CSV file' do
      # don't comparing xlsx files here
      subject
      expect(File.exists?(xls_path)).to be_true
    end

    it 'raises when the source file was not found' do
      expect{described_class.new.convert('/some/non/existing/file.csv', xls_path)}.to raise_error(ArgumentError, /file not found/)
    end

    it 'raises when the destination file already exists' do
      expect{described_class.new.convert('/some/non/existing/file.csv', Tempfile.new('blafoo').path)}.to raise_error(ArgumentError, /destination file exists/)
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sepparator-0.0.3 spec/sepparator/spreadsheet_converter_spec.rb
sepparator-0.0.2 spec/sepparator/spreadsheet_converter_spec.rb
sepparator-0.0.1 spec/sepparator/spreadsheet_converter_spec.rb