Sha256: f988fa9009c7e3737d229c455e37fbcbffd5fcdf64e76fb97c11a3004ff1ac19

Contents?: true

Size: 1.1 KB

Versions: 38

Compression:

Stored size: 1.1 KB

Contents

require 'spec_helper'

describe Picky::API::Tokenizer do
  let(:object) do
    Class.new do
      include Picky::API::Tokenizer
    end.new
  end
  context 'extract_tokenizer' do
    context 'options hash' do
      it 'creates a tokenizer' do
        object.extract_tokenizer(indexing: { splits_text_on: /\t/ }).
          tokenize("hello\tworld").should == [['hello', 'world'], ['hello', 'world']]
      end
    end
    context 'tokenizer' do
      let(:tokenizer) do
        Class.new do
          def tokenize text
            ['unmoved', 'by', 'your', 'texts']
          end
        end.new
      end
      it 'creates a tokenizer' do
        object.extract_tokenizer(tokenizer).
          tokenize("hello\tworld").should == ['unmoved', 'by', 'your', 'texts']
      end
    end
    context 'invalid tokenizer' do
      it 'raises with a nice error message' do
        expect {
          object.extract_tokenizer Object.new
        }.to raise_error(<<-ERROR)
indexing options should be either
* a Hash
or
* an object that responds to #tokenize(text) => [[token1, ...], [original1, ...]]
ERROR
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
picky-4.6.3 spec/lib/api/tokenizer_spec.rb
picky-4.6.2 spec/lib/api/tokenizer_spec.rb
picky-4.6.1 spec/lib/api/tokenizer_spec.rb
picky-4.6.0 spec/lib/api/tokenizer_spec.rb
picky-4.5.12 spec/lib/api/tokenizer_spec.rb
picky-4.5.11 spec/lib/api/tokenizer_spec.rb
picky-4.5.10 spec/lib/api/tokenizer_spec.rb
picky-4.5.9 spec/lib/api/tokenizer_spec.rb
picky-4.5.8 spec/lib/api/tokenizer_spec.rb
picky-4.5.7 spec/lib/api/tokenizer_spec.rb
picky-4.5.6 spec/lib/api/tokenizer_spec.rb
picky-4.5.5 spec/lib/api/tokenizer_spec.rb
picky-4.5.4 spec/lib/api/tokenizer_spec.rb
picky-4.5.3 spec/lib/api/tokenizer_spec.rb
picky-4.5.2 spec/lib/api/tokenizer_spec.rb
picky-4.5.1 spec/lib/api/tokenizer_spec.rb
picky-4.5.0 spec/lib/api/tokenizer_spec.rb
picky-4.4.2 spec/lib/api/tokenizer_spec.rb
picky-4.4.1 spec/lib/api/tokenizer_spec.rb
picky-4.4.0 spec/lib/api/tokenizer_spec.rb