Sha256: 41566aa946af60d46b9a11dca3f8c4324e109fb35ccfa69d2e2dd6cb5b97a375

Contents?: true

Size: 1.58 KB

Versions: 4

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'

describe Roo::Spreadsheet do
  describe '.open' do
    context 'when the file extension is uppercase' do
      let(:filename) { 'file.XLS' }

      it 'loads the proper type' do
        expect(Roo::Excel).to receive(:new).with(filename, {})
        Roo::Spreadsheet.open(filename)
      end
    end

    context 'for a url' do
      context 'that is csv' do
        let(:filename) { 'http://example.com/file.csv?with=params#and=anchor' }

        it 'treats the url as CSV' do
          expect(Roo::CSV).to receive(:new).with(filename, {})
          Roo::Spreadsheet.open(filename)
        end
      end
    end

    context 'for a csv file' do
      let(:filename) { 'file.csv' }
      let(:options) { {csv_options: {col_sep: '"'}} }

      context 'with options' do
        it 'passes the options through' do
          expect(Roo::CSV).to receive(:new).with(filename, options)
          Roo::Spreadsheet.open(filename, options)
        end
      end
    end

    context 'when the file extension' do
      let(:filename) { 'file.xls' }

      context "is xls" do
        let(:options) { { extension: "xls" } }

        it 'loads with xls extension options' do
          expect(Roo::Excel).to receive(:new).with(filename, options)
          Roo::Spreadsheet.open(filename, options)
        end
      end

      context "is .xls" do
        let(:options) { { extension: ".xls" } }

        it 'loads with .xls extension options' do
          expect(Roo::Excel).to receive(:new).with(filename, options)
          Roo::Spreadsheet.open(filename, options)
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/roo-1.13.2/spec/lib/roo/spreadsheet_spec.rb
roo-1.13.2 spec/lib/roo/spreadsheet_spec.rb
roo-1.13.1 spec/lib/roo/spreadsheet_spec.rb
roo-1.13.0 spec/lib/roo/spreadsheet_spec.rb