Module Sphincter::SearchStub
In: lib/sphincter/search_stub.rb

Stub for Sphincter searching. Extend ActiveRecord::Base with this module in your tests so you won‘t have to run a Sphinx searchd to test your searching.

In test/testHelper.rb:

  require 'sphincter/search_stub'
  ActiveRecord::Base.extend Sphincter::SearchStub

Before running a search, you‘ll need to populate the stub‘s accessors:

  def test_search
    Model.search_args = []
    Model.search_results = [Model.find(1, 2, 3)]

    records = Model.search 'query'

    assert_equal 1, Model.search_args.length
    assert_equal [...], Model.search_args
    assert_equal 0, Model.search_results.length
  end

Since both search_args and search_results are an Array you can call search multiple times and get back different results per call. search will raise an exception if you don‘t supply enough results.

Methods

search  

Attributes

search_args  [RW]  An Array that records arguments search was called with. search_args isn‘t set to anything by default, so do that in your test setup.
search_results  [RW]  A pre-populated Array of search results for queries. search_results isn‘t set to anything by default, so do that in your test setup.

Public Instance methods

Overrides Sphincter::Search#search to use the search_args and search_results values instead of connecting to Sphinx.

[Validate]