Sha256: 7b2ae86b373095a9ee3eba115682eed3c05c6b9a5370bd30a0ae683226cda0f9

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Zizia::CsvFormatValidator do
  subject(:validator)  { described_class.new }
  let(:invalid_parser) { Zizia::CsvParser.new(file: invalid_file) }
  let(:invalid_file)   { File.open('spec/fixtures/bad_example.csv') }

  it_behaves_like 'a Zizia::Validator' do
    let(:valid_parser)   { Zizia::CsvParser.new(file: valid_file) }
    let(:valid_file)     { File.open('spec/fixtures/example.csv') }
  end

  define :a_validator_error do
    match do |error|
      return false unless error.respond_to?(:validator)

      if fields
        return false if fields[:validator] && error.validator != fields[:validator]
        return false if fields[:name]      && error.name      != fields[:name]
      end

      true
    end

    chain :with, :fields
  end

  describe '#validate' do
    it 'returns a Validator::Error' do
      expect(validator.validate(parser: invalid_parser))
        .to contain_exactly a_validator_error
        .with(validator: validator.class,
              name: CSV::MalformedCSVError)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zizia-6.0.1 spec/zizia/csv_format_validator_spec.rb