Sha256: 6e4f1ed66686293cff649cfab35c27d6b117d55901b299cea68e4a866eabca62

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

require 'spec_helper'

module Csv2hash
  describe 'Validator' do

    describe '#message' do
      let(:cell) { double(:cell, rules: rules) }

      subject do
        Class.new do
          include Validator
        end.new
      end

      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, cell, nil, nil)).to eql 'bar are value of foo key'
        end
      end

      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, cell, nil, nil)).to eql '["bar", "zone"] are values of foo key'
        end
      end

      context 'with position' do
        let(:rules) { { message: 'value not found on :position' } }

        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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
csv2hash-0.6.4 spec/csv2hash/validator_spec.rb
csv2hash-0.6.3 spec/csv2hash/validator_spec.rb
csv2hash-0.6.2 spec/csv2hash/validator_spec.rb
csv2hash-0.6.1 spec/csv2hash/validator_spec.rb
csv2hash-0.6.0 spec/csv2hash/validator_spec.rb