Sha256: 9636978fd9056d65fc8d472ad05f0a2306e1b5af38c447f0a85b2196e3e1546a

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

require 'spec_helper'

describe ThinkingSphinx::Excerpter do
  let(:excerpter)  { ThinkingSphinx::Excerpter.new('index', 'all words') }
  let(:config)     { double('config', :connection => connection) }
  let(:connection) {
    double('connection', :query => [{'snippet' => 'some highlighted words'}])
  }

  before :each do
    ThinkingSphinx::Configuration.stub :instance => config
    Riddle::Query.stub :snippets => 'CALL SNIPPETS'
  end

  describe '#excerpt!' do
    it "generates a snippets call" do
      Riddle::Query.should_receive(:snippets).
        with('all of the words', 'index', 'all words',
          ThinkingSphinx::Excerpter::DefaultOptions).
        and_return('CALL SNIPPETS')

      excerpter.excerpt!('all of the words')
    end

    it "respects the provided options" do
      excerpter = ThinkingSphinx::Excerpter.new('index', 'all words',
        :before_match => '<b>', :chunk_separator => ' -- ')

      Riddle::Query.should_receive(:snippets).
        with('all of the words', 'index', 'all words',
          :before_match => '<b>', :after_match => '</span>',
          :chunk_separator => ' -- ').
        and_return('CALL SNIPPETS')

      excerpter.excerpt!('all of the words')
    end

    it "sends the snippets call to Sphinx" do
      connection.should_receive(:query).with('CALL SNIPPETS').
        and_return([{'snippet' => ''}])

      excerpter.excerpt!('all of the words')
    end

    it "returns the first value returned by Sphinx" do
      connection.stub :query => [{'snippet' => 'some highlighted words'}]

      excerpter.excerpt!('all of the words').should == 'some highlighted words'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thinking-sphinx-3.0.0.pre spec/thinking_sphinx/excerpter_spec.rb