Sha256: cc9dc693ea620098de51dbd3a8c5c8358c2476729508b62320d09c33b8b9d124
Contents?: true
Size: 1.49 KB
Versions: 1
Compression:
Stored size: 1.49 KB
Contents
require 'spec_helper' describe Csv2hash::StructureValidator do let(:rules) { [ { position: [0,0], key: 'name' } ] } let(:options) { {} } let(:definition) do Csv2hash::Definition.new(rules, Csv2hash::Definition::MAPPING, options).tap do |definition| definition.validate! definition.default! end end subject do Csv2hash.new(definition, 'file_path', true, data_source) end context '#MaxColumns' do let(:options){ { structure_rules: { 'MaxColumns' => 2 } } } context 'valid data' do let(:data_source) do [ [ 'John', 'Doe' ] ] end it { expect { subject.validate_structure! }.to_not raise_error } end context 'invalid data' do let(:data_source) do [ [ 'John', 'Doe' ], [ 'Jane', 'Doe', 'extra field' ] ] end it { expect { subject.validate_structure! }.to raise_error 'Too many columns (max. 2) on line 1' } end end context '#MinColumns' do let(:options){ { structure_rules: { 'MinColumns' => 2 } } } context 'valid data' do let(:data_source) do [ [ 'John', 'Doe', 'foo' ] ] end it { expect { subject.validate_structure! }.to_not raise_error } end context 'invalid data' do let(:data_source) do [ [ 'John' ], [ 'Jane', 'Doe' ] ] end it { expect { subject.validate_structure! }.to raise_error 'Not enough columns (min. 2) on line 0' } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
csv2hash-0.2.0 | spec/csv2hash/structure_validator_spec.rb |