6

我想编写我常用的 RSpec/Capybara 请求规范来测试使用 Sunspot 和 Solr 的搜索功能。我一直在挖掘,但找不到如何让它工作。我安装了 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 失败。提交似乎不起作用

任何使用太阳黑子的测试都应该如下......

describe "search", :search => true do

并确保您的 spec_helper.rb 中有以下内容

require 'sunspot_test/rspec'
于 2011-11-09T16:46:20.377 回答