Eri*_* M. 6 testing solr rspec sunspot ruby-on-rails-3
我想编写我常用的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
Run Code Online (Sandbox Code Playgroud)
你可能犯了同样的错误.在这里看到我的帖子的答案 - 太阳黑子和RSpec失败.提交似乎没有起作用
任何使用太阳黑子的测试应如下....
describe "search", :search => true do
Run Code Online (Sandbox Code Playgroud)
并确保spec_helper.rb中包含以下内容
require 'sunspot_test/rspec'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1159 次 |
| 最近记录: |