ruby-on-rails-3 - 如何使用 Capybara/RSpec 编写请求规范以测试 Sunspot/Solr 搜索?

标签 ruby-on-rails-3 testing solr rspec sunspot

我想编写我常用的 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

最佳答案

您可能犯了和我一样的错误。在这里查看我的帖子的答案 - Sunspot and RSpec fail. The commit doesn't seem to be working

任何使用 Sunspot 的测试都应该如下......

describe "search", :search => true do

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

require 'sunspot_test/rspec'

关于ruby-on-rails-3 - 如何使用 Capybara/RSpec 编写请求规范以测试 Sunspot/Solr 搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6989024/

相关文章:

android - "Monkey Runner"对测试人员直接在Android应用程序中准备测试用例有用吗?

ruby-on-rails - rake 太阳黑子 :solr:reindex not working in Rails 4 app with multiple engines

search - Lucene 或 Mysql 全文搜索

javascript - 如何在 View 中将变量从 Controller 传递到 JavaScript?

ruby - 使用 headless Chrome 将 URL 列入黑名单

ruby-on-rails - buggy Rails 应用程序 : test or refactor?

solr - 如何配置具有多个核心的 Solr 复制

ruby - routes.rb 中动态路由的 Rails 访问请求

ruby-on-rails - 如何使用 wicked_pdf 将 pdf 文件保存在公用文件夹中

ruby-on-rails-3 - Rails3 SSL 路由问题