collectiveidea/sunspot_test — Issue #9: Sunspot.commit doesn't seem to make any difference
Author: simmogs
Created: 2011-11-08 09:52:46+00:00
State: open

Hi there,

I have a number of tests in both RSpec and Cucumber that are displaying the same behaviour.

When records are added, they show up in the DB, but for some reason no results are found in Sunspot. When I repeat the test manually everything works, so I'm happy that the code is ok. It would still be nice to get the tests working though!

As per the instructions, I am calling Sunspot.commit, but it doesn't seem to make any difference. I've checked and the Sunspot instance in definitely starting when the tests are running as it should.

It's hard to debug this one as there aren't any error messages, it just doesn't give the expected result.

A very abbreviated version of my Gemfile is below

gem "rails", "~> 3.1.1"
gem 'mysql2'

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

group :development, :test do
gem "mongrel"
gem "rspec-rails"
gem "capybara"
gem 'ruby-debug'
gem 'database_cleaner'
gem 'factory_girl_rails'
gem 'cucumber-rails'
gem 'ci_reporter'
gem 'autotest-rails'
gem 'launchy'
gem 'email_spec'
gem 'shoulda-matchers'
end

And below is an example of a failing test.

Background:
Given I am an anonymous user
And I am on the home page
And there is 1 private article in the database
And the sunspot index is up to date

Scenario: Searching for public article
Given there is 1 public article in the database
And the sunspot index is up to date
When I fill in "search" with "Public"
And I press "search_submit"

Then there should be 2 articles in the database
And there should be 1 public article in the database

Then I should see "Found 1 result"
And I should see "Public"

The test fails on the "Found 1 result" line.

Cheers,
Graeme