Sha256: eca805512b06e76e04c6770908e71fa6a95ce287416b2e3dd3e05cc7baa6518c

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

$LOAD_PATH << '../lib'
require 'regex_sieve'

describe RegexSieve do
    before do
      @sieve = RegexSieve.new({
        /(Invincible|Born & Raised) IPA/ => 'Craft IPA',
        /(Fresh Squeezed) IPA/           => 'Microbrew IPA',
        /IPA/                            => 'Other IPA'
      })
    end

  describe 'looking up a value' do
    it 'returns the value of the first match' do
      expect(@sieve['Invincible IPA']).to eq 'Craft IPA'
    end

    it 'is not just a hash lookup' do
      expect(@sieve['Random IPA']).to eq 'Other IPA'
    end

    it 'returns nil if no match is found' do
      expect(@sieve['Does not match']).to be nil
    end
  end

  describe 'using matching groups' do
    it 'returns the match groups when specified' do
      match = @sieve['Invincible IPA', :match][:match][1]
      expect(match).to eq 'Invincible'
    end
  end

  describe 'using regex and matching groups' do
    it 'returns the matched regex when specified' do
      regex = @sieve['Invincible IPA', :regex, :match][:regex]
      expect(regex).to eq /(Invincible|Born & Raised) IPA/
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
regex_sieve-0.1.0 spec/regex_sieve_spec.rb