Sha256: 13a33d52c77c3737da5d98ddc49930615ba94bc665e86c04d7f983a02b4f3797

Contents?: true

Size: 1.08 KB

Versions: 11

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Zizia::CsvFormatValidator do
  subject(:validator)  { described_class.new(error_stream: []) }
  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

11 entries across 11 versions & 1 rubygems

Version Path
zizia-2.1.0.alpha.09 spec/zizia/csv_format_validator_spec.rb
zizia-2.1.0.alpha.08 spec/zizia/csv_format_validator_spec.rb
zizia-2.1.0.alpha.07 spec/zizia/csv_format_validator_spec.rb
zizia-2.1.0.alpha.06 spec/zizia/csv_format_validator_spec.rb
zizia-2.1.0.alpha.05 spec/zizia/csv_format_validator_spec.rb
zizia-2.1.0.alpha.04 spec/zizia/csv_format_validator_spec.rb
zizia-2.1.0.alpha.03 spec/zizia/csv_format_validator_spec.rb
zizia-2.1.0.alpha.02 spec/zizia/csv_format_validator_spec.rb
zizia-2.1.0.alpha.01 spec/zizia/csv_format_validator_spec.rb
zizia-2.0.0.alpha.01 spec/zizia/csv_format_validator_spec.rb
zizia-1.0.1 spec/zizia/csv_format_validator_spec.rb