How can I write a query specification with Capybara / RSpec to test Sunspot / Solr searches?

I would like to write my usual RSpec / Capybara query specifications to test search capabilities with Sunspot and Solr. I was digging, but I can not find how to do it. I have installed sunspot_test gem and verified that the created products exist. Maybe the problem is with indexing? 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 
+6
source share
1 answer

You probably made the same mistake as me. See the answer to my post here - Sunspot and RSpec fail. Commit does not work

Any test that uses Sunspot should be as follows.

 describe "search", :search => true do 

and make sure in your spec_helper.rb

there is the following:
 require 'sunspot_test/rspec' 
+5
source

Source: https://habr.com/ru/post/894587/


All Articles