spec/csv2hash/validator_spec.rb in csv2hash-0.5.0 vs spec/csv2hash/validator_spec.rb in csv2hash-0.6.0
- old
+ new
@@ -1,40 +1,41 @@
require 'spec_helper'
-describe Csv2hash::Validator do
+module Csv2hash
+ describe 'Validator' do
- let(:definition) do
- Csv2hash::Definition.new([ { position: [0,0], key: 'name' } ], Csv2hash::Definition::MAPPING).tap do |definition|
- definition.validate!
- definition.default!
- end
- end
+ describe '#message' do
+ let(:cell) { double(:cell, rules: rules) }
- describe '#message' do
- subject { Csv2hash::Main.new double('definition', type: Csv2hash::Definition::COLLECTION), nil }
+ subject do
+ Class.new do
+ include Validator
+ end.new
+ end
- context 'string value' do
- let(:rule) { { foo: 'bar', message: ':foo are value of foo key' } }
+ context 'string value' do
+ let(:rules) {{ foo: 'bar', message: ':foo are value of foo key' }}
- it 'substitue value of key' do
- expect(subject.send(:message, rule, nil, nil)).to eql 'bar are value of foo key'
+ it 'substitue value of key' do
+ expect(subject.send(:message, cell, nil, nil)).to eql 'bar are value of foo key'
+ end
end
- end
- context 'array value' do
- let(:rule) { { foo: ['bar', 'zone'], message: ':foo are values of foo key' } }
+ context 'array value' do
+ let(:rules) { { foo: ['bar', 'zone'], message: ':foo are values of foo key' } }
- it 'substitue value of key' do
- expect(subject.send(:message, rule, nil, nil)).to eql '["bar", "zone"] are values of foo key'
+ it 'substitue value of key' do
+ expect(subject.send(:message, cell, nil, nil)).to eql '["bar", "zone"] are values of foo key'
+ end
end
- end
- context 'with position' do
- let(:rule) { { message: 'value not found on :position' } }
+ context 'with position' do
+ let(:rules) { { message: 'value not found on :position' } }
- it 'substitue value of key' do
- expect(subject.send(:message, rule, 0, 2)).to eql 'value not found on [0, 2]'
+ it 'substitue value of key' do
+ expect(subject.send(:message, cell, 0, 2)).to eql 'value not found on [0, 2]'
+ end
end
end
- end
+ end
end