Sunspot and RSpec fail. The commit doesn't seem to be working

时间秒杀一切 提交于 2019-12-07 09:04:57

问题


I've got a few tests running with RSpec for a Rails site, but despite following the instructions things aren't quite behaving themselves.

I create an article via a Factory, run Sunspot.commit and then check the results. I always seem to draw a blank though. When I test it manually via the console or through the website it all works find though.

Any ideas? How can I output the sunspot logs to see what's going on?

My Gemfile has the following, and I'm running Rails 3.1.1

gem 'sunspot', '1.2.1'
gem 'sunspot_rails'
gem 'sunspot_test'

Many thanks, Graeme


回答1:


It was my fault for not reading the manual properly.

https://github.com/collectiveidea/sunspot_test/issues/9

It's necessary to add a magic bit to the description to make sure that Solr is started.

describe "my nice test", :search => true do
  thing = Factory.create(:thing)
  Sunspot.commit
  # do my search and test
  # now it works!
end

It's the :search => true that's important.




回答2:


Just to add a little something to the response above; if using FactoryGirl:

FactoryGirl.define do
    after(:create) { Sunspot.commit } 
...
end

then you won't have to add the commit call on each test file...



来源:https://stackoverflow.com/questions/7982349/sunspot-and-rspec-fail-the-commit-doesnt-seem-to-be-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!