Sha256: dd612f15e4b1823fb13affc78200c0db5ee43078c42e7e2d6974cd29c0f77dc8

Contents?: true

Size: 1.56 KB

Versions: 28

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

fixture_path = 'spec/fixtures'

describe 'numeric conversion of values' do
  it 'occurs by default' do
    options = {}
    data = SmarterCSV.process("#{fixture_path}/numeric.csv", options)
    data.size.should == 3
    
    # all the keys should be symbols
    data.each do |hash|
      hash[:wealth].should be_a_kind_of(Numeric) unless hash[:wealth].nil?
      hash[:reference].should be_a_kind_of(Numeric) unless hash[:reference].nil?
    end
  end

  it 'can be prevented for all values' do
    options = { :convert_values_to_numeric => false }
    data = SmarterCSV.process("#{fixture_path}/numeric.csv", options)
    
    data.each do |hash|
      hash[:wealth].should be_a_kind_of(String) unless hash[:wealth].nil?
      hash[:reference].should be_a_kind_of(String) unless hash[:reference].nil?
    end
  end

  it 'can be prevented for some keys' do
    options = { :convert_values_to_numeric => { :except => :reference }}
    data = SmarterCSV.process("#{fixture_path}/numeric.csv", options)

    data.each do |hash|
      hash[:wealth].should be_a_kind_of(Numeric) unless hash[:wealth].nil?
      hash[:reference].should be_a_kind_of(String) unless hash[:reference].nil?
    end
  end
  
  it 'can occur only for some keys' do
    options = { :convert_values_to_numeric => { :only => :wealth }}
    data = SmarterCSV.process("#{fixture_path}/numeric.csv", options)

    data.each do |hash|
      hash[:wealth].should be_a_kind_of(Numeric) unless hash[:wealth].nil?
      hash[:reference].should be_a_kind_of(String) unless hash[:reference].nil?
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
smarter_csv-1.6.1 spec/smarter_csv/convert_values_to_numeric_spec.rb
smarter_csv-1.6.0 spec/smarter_csv/convert_values_to_numeric_spec.rb
smarter_csv-1.5.2 spec/smarter_csv/convert_values_to_numeric_spec.rb
smarter_csv-1.5.1 spec/smarter_csv/convert_values_to_numeric_spec.rb
smarter_csv-1.5.0 spec/smarter_csv/convert_values_to_numeric_spec.rb
smarter_csv-1.4.2 spec/smarter_csv/convert_values_to_numeric_spec.rb
smarter_csv-1.4.0 spec/smarter_csv/convert_values_to_numeric_spec.rb
smarter_csv-1.3.0 spec/smarter_csv/convert_values_to_numeric_spec.rb
smarter_csv-1.2.8 spec/smarter_csv/convert_values_to_numeric_spec.rb
smarter_csv-1.2.7 spec/smarter_csv/convert_values_to_numeric_spec.rb
pokedex-terminal-0.2.8 vendor/bundle/ruby/2.7.0/gems/smarter_csv-1.2.6/spec/smarter_csv/convert_values_to_numeric_spec.rb
pokedex-terminal-0.2.7 vendor/bundle/ruby/2.7.0/gems/smarter_csv-1.2.6/spec/smarter_csv/convert_values_to_numeric_spec.rb
pokedex-terminal-0.2.6 vendor/bundle/ruby/2.7.0/gems/smarter_csv-1.2.6/spec/smarter_csv/convert_values_to_numeric_spec.rb
pokedex-terminal-0.2.5 vendor/bundle/ruby/2.7.0/gems/smarter_csv-1.2.6/spec/smarter_csv/convert_values_to_numeric_spec.rb
pokedex-terminal-0.2.4 vendor/bundle/ruby/2.7.0/gems/smarter_csv-1.2.6/spec/smarter_csv/convert_values_to_numeric_spec.rb
smarter_csv-1.2.6 spec/smarter_csv/convert_values_to_numeric_spec.rb
smarter_csv-1.2.5 spec/smarter_csv/convert_values_to_numeric_spec.rb
smarter_csv-1.2.4 spec/smarter_csv/convert_values_to_numeric_spec.rb
smarter_csv-1.2.3 spec/smarter_csv/convert_values_to_numeric_spec.rb
smarter_csv-1.2.0 spec/smarter_csv/convert_values_to_numeric_spec.rb