Ruby on rails 3 如何使用Capybara/RSpec编写用于测试太阳黑子/Solr搜索的请求规范?

Ruby on rails 3 如何使用Capybara/RSpec编写用于测试太阳黑子/Solr搜索的请求规范?,ruby-on-rails-3,testing,solr,rspec,sunspot,Ruby On Rails 3,Testing,Solr,Rspec,Sunspot,我想编写我常用的RSpec/Capybara请求规范,用Sunspot和Solr测试搜索功能。我一直在四处寻找,但找不到如何让它工作。我已经安装了sunspot_测试gem,并验证了创建的产品确实存在。问题似乎与索引有关,也许?我错过了什么 require 'spec_helper' describe "search" do context "when searching by name/description" do let!(:super_mario_bros_3) { F

我想编写我常用的RSpec/Capybara请求规范,用Sunspot和Solr测试搜索功能。我一直在四处寻找,但找不到如何让它工作。我已经安装了sunspot_测试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

你可能犯了和我一样的错误。在这里查看我帖子的答案-

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

describe "search", :search => true do
并确保spec_helper.rb中包含以下内容

require 'sunspot_test/rspec'