Example of thinking sphinx unit testing:
My environment:
psql (PostgreSQL) 8.3.7
sphinx 0.9.8.1

Based on article 
http://opensoul.org/2009/6/1/cucumber-scenarios-that-depend-on-sphinx

I created two methods in test_helper.rb

  def start_sphinx
    @thinking_sphinx = ThinkingSphinx::Configuration.instance
    @thinking_sphinx.build
    FileUtils.mkdir_p @thinking_sphinx.searchd_file_path
    @thinking_sphinx.controller.index
    @thinking_sphinx.controller.start
  end

  def stop_sphinx
    @thinking_sphinx.controller.stop
    DatabaseCleaner.clean
  end

You need also gem database_cleaner

Now I can write in my tests (shoulda):

  context "user search" do
    setup do
      User.create(:login => 'johndoe')
      start_sphinx
    end
    teardown { stop_sphinx }

    should "find john doe" do
      u = User.search "johndoe"
      assert 'johndoe', u.first.login
      assert 1, u.size
    end
  end

Maybe it will help someone.
If you know better way to do this, post a note.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to