I'd like to write my usual RSpec/Capybara request specs to test search functionality using Sunspot and Solr. I've been digging around but can't find how to get this working. I have the sunspot_test gem installed and have verified that the Products created do exist. The issue seems to be with the indexing, maybe? What am I missing?
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
You're probably making the same mistake that I did. See the answer to my post here - Sunspot and RSpec fail. The commit doesn't seem to be working
Any test which uses Sunspot should be as follows....
describe "search", :search => true do
and make sure you have the following in your spec_helper.rb
require 'sunspot_test/rspec'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With