Sha256: fc11a46071717efeb131db4b92986a7af7c74cfa8859952b977f3c0442cf6fde

Contents?: true

Size: 1.24 KB

Versions: 13

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

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

describe CSVDecision::Matchers::Numeric do
  subject { described_class.new }

  describe '#new' do
    it { is_expected.to be_a CSVDecision::Matchers::Numeric }
    it { is_expected.to respond_to(:matches?).with(1).argument }
  end

  describe '#matches?' do
    matcher = described_class.new

    context 'comparison matches value' do
      data = [
          ['< 1',  0],
          ['< 1', '0'],
          ['> 1',  5],
          ['!= 1',  0],
          ['> 1', '5'],
          ['>= 1.1', BigDecimal('1.1')],
          ['<=-1.1', BigDecimal('-12')]
      ]

      data.each do |cell, value|
        it "comparision #{cell} matches #{value}" do
          proc = matcher.matches?(cell)
          expect(proc).to be_a(CSVDecision::Matchers::Proc)
          expect(proc.type).to eq :proc
          expect(proc.function[value]).to eq true
        end
      end
    end

    context 'does not match non-numeric comparision' do
      data = ['1', ':column', ':= nil', ':= true', ':= 0', 'abc', 'abc.*def', '-1..1', '0...3']

      data.each do |cell|
        it "cell #{cell} is not a comparision}" do
          expect(matcher.matches?(cell)).to eq false
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
csv_decision2-0.5.1 spec/csv_decision/matchers/numeric_spec.rb
csv_decision-0.5.1 spec/csv_decision/matchers/numeric_spec.rb
csv_decision-0.5.0 spec/csv_decision/matchers/numeric_spec.rb
csv_decision-0.4.1 spec/csv_decision/matchers/numeric_spec.rb
csv_decision-0.4.0 spec/csv_decision/matchers/numeric_spec.rb
csv_decision-0.3.2 spec/csv_decision/matchers/numeric_spec.rb
csv_decision-0.3.1 spec/csv_decision/matchers/numeric_spec.rb
csv_decision-0.3.0 spec/csv_decision/matchers/numeric_spec.rb
csv_decision-0.2.0 spec/csv_decision/matchers/numeric_spec.rb
csv_decision-0.1.0 spec/csv_decision/matchers/numeric_spec.rb
csv_decision-0.0.9 spec/csv_decision/matchers/numeric_spec.rb
csv_decision-0.0.8 spec/csv_decision/matchers/numeric_spec.rb
csv_decision-0.0.7 spec/csv_decision/matchers/numeric_spec.rb