Sha256: 9801451c142d3e5eb069c4339eeb886c05444206cab14fabf56ec6558bd892ac

Contents?: true

Size: 1.72 KB

Versions: 16

Compression:

Stored size: 1.72 KB

Contents

require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')

describe Attributor::CSV do
  subject!(:csv) { Attributor::CSV.of(Integer) }

  context '.load' do
    let!(:array) { (1..10).to_a }
    let!(:value) { array.join(',') }

    it 'parses the value and returns an array with the right types' do
      expect(csv.load(value)).to match_array array
    end
  end

  context '.example' do
    let!(:example) { csv.example }
    let!(:loaded_example) { csv.load(example) }

    it 'generates a String example' do
      expect(example).to be_a(String)
    end

    it 'generates a comma-separated list of Integer values' do
      expect(loaded_example).to be_a(csv)
      expect(loaded_example.size).to be > 1
      loaded_example.each { |e| expect(e).to be_a(Integer) }
    end
  end

  context '.dump' do
    let!(:int_vals) { [1, 2, 3] }
    let!(:str_vals) { (0..2).collect { /\w+/.gen } }

    it 'dumps a String value' do
      expect(csv.dump(int_vals)).to be_a(String)
    end

    it 'dumps a comma-separated list of Integers' do
      expect(csv.dump(int_vals)).to eq(int_vals.join(','))
    end

    it 'dumps non-Integer values also' do
      expect(csv.dump(str_vals)).to eq(str_vals.join(','))
    end

    it 'dumps nil values as nil' do
      expect(csv.dump(nil)).to eq(nil)
    end
  end

  context '.describe' do
    let(:example) { csv.example }
    subject(:described) { csv.describe(example: example) }
    it 'adds a string example if an example is passed' do
      expect(described).to have_key(:example)
      expect(described[:example]).to eq(csv.dump(example))
    end
    it 'ensures no member_attribute key exists from underlying Collection' do
      expect(described).not_to have_key(:member_attribute)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
attributor-7.1 spec/types/csv_spec.rb
attributor-7.0 spec/types/csv_spec.rb
attributor-6.5 spec/types/csv_spec.rb
attributor-6.4 spec/types/csv_spec.rb
attributor-6.3 spec/types/csv_spec.rb
attributor-6.2 spec/types/csv_spec.rb
attributor-6.1 spec/types/csv_spec.rb
attributor-6.0 spec/types/csv_spec.rb
attributor-5.7 spec/types/csv_spec.rb
attributor-5.6 spec/types/csv_spec.rb
attributor-5.5 spec/types/csv_spec.rb
attributor-5.4 spec/types/csv_spec.rb
attributor-5.3 spec/types/csv_spec.rb
attributor-5.2.1 spec/types/csv_spec.rb
attributor-5.2.0 spec/types/csv_spec.rb
attributor-5.1.0 spec/types/csv_spec.rb