Sha256: e3017cefac56fcee46b736b6b86c350ec06187026699f8f114f923c75f4d578f

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'

describe Csv2hash::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
    subject { Csv2hash::Main.new double('definition', type: Csv2hash::Definition::COLLECTION), nil }

    context 'string value' do
      let(:rule) { { 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'
      end
    end

    context 'array value' do
      let(:rule) { { 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'
      end
    end

    context 'with position' do
      let(:rule) { { 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]'
      end
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
csv2hash-0.5.0 spec/csv2hash/validator_spec.rb
csv2hash-0.4.0 spec/csv2hash/validator_spec.rb
csv2hash-0.3.0 spec/csv2hash/validator_spec.rb