Sha256: 3f274f8b33e300fd936c01352b5c775aab4a39046f66871eea62bad309ce6c98

Contents?: true

Size: 1.28 KB

Versions: 8

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require_relative '../../lib/csv_decision'

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

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

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

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

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

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

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

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

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
csv_decision2-0.5.1 spec/csv_decision/parse_spec.rb
csv_decision-0.5.1 spec/csv_decision/parse_spec.rb
csv_decision-0.5.0 spec/csv_decision/parse_spec.rb
csv_decision-0.4.1 spec/csv_decision/parse_spec.rb
csv_decision-0.4.0 spec/csv_decision/parse_spec.rb
csv_decision-0.3.2 spec/csv_decision/parse_spec.rb
csv_decision-0.3.1 spec/csv_decision/parse_spec.rb
csv_decision-0.3.0 spec/csv_decision/parse_spec.rb