6

Sunspot と Solr を使用して検索機能をテストするために、いつもの RSpec/Capybara リクエスト仕様を書きたいと思います。私は掘り下げてきましたが、これを機能させる方法が見つかりません。私は sunspot_test gem をインストールし、作成された製品が存在することを確認しました。問題はインデックス作成にあるようです。私は何が欠けていますか?

require 'spec_helper'

describe "search" do

  context "when searching by name/description" do

    let!(:super_mario_bros_3) { Factory(:product, :name => 'Super Mario Bros. 3') }
    let!(:legend_of_zelda)    { Factory(:product, :name => 'Legend of Zelda') }

    before { Product.reindex; Sunspot.commit }


    it "should only find games matching the search text", :js => true, :search => true do
      # search_for fills in and submits the search form
      search_for("Super")

      # This yields an empty array
      p Product.search { keyword "super" }.results

      # These fail
      page.should have_content super_mario_bros_3.name
      page.should have_no_content legend_of_zelda.name
    end

  end

end
4

1 に答える 1

5

あなたはおそらく私がしたのと同じ間違いをしている. ここで私の投稿への回答を参照してください-SunspotとRSpecは失敗します。コミットが機能していないようです

Sunspot を使用するすべてのテストは、次のようにする必要があります....

describe "search", :search => true do

spec_helper.rb に以下があることを確認してください

require 'sunspot_test/rspec'
于 2011-11-09T16:46:20.377 に答える