Sha256: cae4ca18f0f2c3dafdd466818620ba3c879f20d7dd727428ee9aca6d6239294c

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 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.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
        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, 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csv2hash-0.2.1 spec/csv2hash/validator_spec.rb