spec/csv2hash/validator_spec.rb in csv2hash-0.0.1 vs spec/csv2hash/validator_spec.rb in csv2hash-0.0.2
- old
+ new
@@ -1,47 +1,46 @@
require 'spec_helper'
describe Validator do
let(:definition) do
- Definition.new.tap do |definition|
- definition.type = Definition::MAPPING
- definition.rules = [ { position: [0,0], key: 'name' } ]
+ Definition.new([ { position: [0,0], key: 'name' } ], Definition::MAPPING).tap do |definition|
definition.validate!
definition.default!
end
end
subject do
- Csv2hash.new definition, data_source
+ Csv2hash.new(definition, 'file_path').tap do |csv2hash|
+ csv2hash.data_source = data_source
+ end
end
- context 'with valid data' do
- let(:data_source) { [ [ 'John Doe' ] ]}
- it { expect { subject.validate_data! }.to_not raise_error }
- end
-
- context 'with invalid data' do
- let(:data_source) { [ [ ] ]}
- it { expect { subject.validate_data! }.to raise_error('undefined name on [0, 0]') }
- end
-
describe '#message' do
- subject { Csv2hash.new nil, nil }
+ subject { Csv2hash.new double('definition', type: Definition::COLLECTION), nil }
context 'string value' do
let(:rule) { { foo: 'bar', message: ':foo are value of foo key' } }
it 'substitue value of key' do
- subject.send(:message, rule).should eql 'bar are value of foo key'
+ subject.send(:message, rule, nil, nil).should eql 'bar are value of foo key'
end
end
context 'array value' do
let(:rule) { { foo: ['bar', 'zone'], message: ':foo are values of foo key' } }
it 'substitue value of key' do
- subject.send(:message, rule).should eql '["bar", "zone"] are values of foo key'
+ subject.send(:message, rule, nil, nil).should eql '["bar", "zone"] are values of foo key'
end
end
+
+ context 'with position' do
+ let(:rule) { { message: 'value not found on :position' } }
+
+ it 'substitue value of key' do
+ subject.send(:message, rule, 0, 2).should eql 'value not found on [0, 2]'
+ end
+ end
end
-end
+
+end
\ No newline at end of file