2012-02-02 7 views
2

私はRuby on Railsアプリケーションでスフィンクスとスフィンクスを使ってデータを検索しています。だから、私は私の仕事をチェックするためにこのテストを持っている:Ruby on Rails - Rspecテストでスフィンクスがデータをインデックス化しない

require 'spec_helper' 
require 'thinking_sphinx/test' 

describe SearchesController do 
    render_views 

    #Start search server in test mode 
    before(:all) do 
     ThinkingSphinx::Test.init 
     ThinkingSphinx::Test.start 
    end 

    describe "when signed in" do 
     before(:each) do 
     @user = test_sign_in(Factory(:user)) 
     @micropost = Factory(:micropost, 
           :user => @user, 
           :content => "Test message of user") 
     ThinkingSphinx::Test.index 
     get :find_microposts, :q => @micropost.content      #Sending data (by :q => "Text") 
     end 

     it "should find micropost of user" do 
     response.should have_selector("table.microposts", 
             :content => @micropost.content) 
     end 
    end 
    end 


    #Stop search server in test mode 
    after(:all) do 
     ThinkingSphinx::Test.stop 
    end 
end 

問題がある - ThinkingSphinx::Test.index動作しません。どうして?

sphinx.yml

development: 
    port: 9312 
    ... 

test: 
    port: 9313 
    ... 

私のシステム:

Mac OS X 
PostgreSQL 9 
Rails 3.1.3 
Ruby 1.9.3 
Sphinx 2.0.3-release (r3043) 

答えて

5

あなたはRSpecのでトランザクションの器具を使用していますか? SphinxはRSpecコンテキスト外のデータベースに保存されていないレコードにはアクセスできないためです。スフィンクスは、インデックス付きのデータに追いつくためにも、あなたは四半期またはインデックスの後に半秒を許可する必要があります。

sleep(0.25) 

、私はあなたのコントローラのテストでスフィンクスをスタブ、およびのみ内スフィンクスを実行することをお勧めだろうと述べているすべての(キュウリ/カピバラなどを介した)統合テスト。

+0

「スリープ」のヒントありがとうございます、これは私を狂ってしまいました。 – declan

関連する問題