Sha256: fb16c0a5a8a9f43dbd9a2d96df5f0e977cae468edacff0ba1fc5127557cdfff9

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

require 'spec_helper'

describe Faraday::Response::CSV do
  let(:csv) { Faraday::Response::CSV.new }
  let(:body) { "integer,string\n12,foobar" }

  it "parses valid csv syntax" do
    parsed = csv.on_complete(:body => body)
    expect(parsed).to be_an Array
  end

  it 'raises Faraday::Error::ParsingError on invalid syntax' do
    expect{
      csv.on_complete(:body => ['foo'])
    }.to raise_error Faraday::Error::ParsingError
  end

  context 'with options' do
    let(:options) { { :headers => true } }
    let(:csv) { Faraday::Response::CSV.new(lambda { |env| env }, options) }

    it "parses valid csv syntax" do
      parsed = csv.on_complete(:body => body)
      expect(parsed).to be_a CSV::Table
    end
  end

  context "integration tests" do
    let(:stubs) { Faraday::Adapter::Test::Stubs.new }
    let(:conn) do
      Faraday.new do |conn|
        conn.adapter :test, stubs
        conn.use Faraday::Response::CSV
      end
    end

    it "creates a hash from the body" do
      stubs.get("/csv") {[200, {'Content-Type' => 'text/csv'}, "integer,string\n12,foobar"]}
      expect(conn.get("/csv").body).to be_an Array
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
faraday_csv-0.0.3 spec/faraday/response/csv_spec.rb
faraday_csv-0.0.2 spec/faraday/response/csv_spec.rb
faraday_csv-0.0.1 spec/faraday/response/csv_spec.rb