Sha256: a8f4277bb67abe209153646985a3998ce71096d81f37d9ca9db0914ac33e1ae4

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require_relative '../../lib/csv_decision2'

describe CSVDecision2::Parse do
  it 'rejects an empty decision table' do
    expect { CSVDecision2.parse('') }
      .to raise_error(CSVDecision2::TableValidationError,
                      'table has no header row')
  end

  it 'parses a decision table from a CSV file' do
    file = Pathname(File.join(CSVDecision2.root, 'spec/data/valid', 'valid.csv'))
    result = CSVDecision2.parse(file)

    expected = [
      ['input', '']
    ]

    expect(result).to be_a(CSVDecision2::Table)
    expect(result.rows).to eq expected
  end

  context 'it parses valid CSV files' do
    Dir[File.join(CSVDecision2.root, 'spec/data/valid/*.csv')].each do |file_name|
      pathname = Pathname(file_name)

      it "loads CSV file: #{pathname.basename}" do
        expect { CSVDecision2.parse(pathname) }.not_to raise_error
        expect(CSVDecision2.parse(pathname)).to be_a CSVDecision2::Table
      end
    end
  end

  context 'it rejects invalid CSV files' do
    Dir[File.join(CSVDecision2.root, 'spec/data/invalid/*.csv')].each do |file_name|
      pathname = Pathname(file_name)

      it "rejects CSV file: #{pathname.basename}" do
        expect { CSVDecision2.parse(pathname) }.to raise_error(CSVDecision2::FileError)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csv_decision2-0.5.2 spec/csv_decision2/parse_spec.rb