Sha256: ed418c00eb7a20969f1283ef6c3c4d5848758a2d1f6a40828df6d369377eec40

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'
module Alf
  class Reader
    describe CSV do
      it_should_behave_like "a Reader class"

      describe "without options" do
        let(:input){
          StringIO.new << "size\n10\n20\n"
        }
        let(:expected){
          [{:size => "10"}, {:size => "20"}]
        }
        subject{ reader.to_a }

        describe "when called on a reader directly" do
          let(:reader){
            CSV.new(input)
          }
          it{ should eq(expected) }
        end

        describe "when called through registered one" do
          let(:reader){
            Reader.reader(Path.dir / 'input.csv')
          }
          it{ should eq(expected) }
        end

        describe "when called through factory method" do
          let(:reader){
            Reader.csv(input)
          }
          it{ should eq(expected) }
        end
      end

      describe "with options" do
        let(:input){
          StringIO.new << "size;name\n10;blambeau\n20;mmathieu\n"
        }
        let(:options){
          {:col_sep => ";"}
        }
        let(:expected){
          [{:size => "10", :name => 'blambeau'}, {:size => "20", :name => 'mmathieu'}]
        }
        subject{ reader.to_a }

        describe "when called on a reader directly" do
          let(:reader){
            CSV.new(input, options)
          }
          it{ should eq(expected) }
        end

        describe "when called through factory method" do
          let(:reader){
            Reader.csv(input, options)
          }
          it{ should eq(expected) }
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alf-core-0.15.0 spec/unit/alf-io/reader/test_csv.rb
alf-core-0.14.0 spec/unit/alf-io/reader/test_csv.rb
alf-core-0.13.1 spec/unit/alf-io/reader/test_csv.rb
alf-core-0.13.0 spec/unit/alf-io/reader/test_csv.rb