Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Auto-starts solr for your tests
Latest commit 1b9e5a6 @ersatzryan ersatzryan Merge pull request #18 from aaronjensen/patch-1
Use before :each instead of before :all for rspec


Gem Version Build Status Code Climate Coverage Status Dependency Status

How to install

Install this sunspot_test from rubygems either directly:

gem install sunspot_test

Or through bundler

# in Gemfile
gem "sunspot_test"

Then in Cucumber's env.rb:

require 'sunspot_test/cucumber'

What does it do?

This gem will automatically start and stop solr for cucumber tests when using the @search tag. For instance, if you have a searchable book model this will allow you to create/query/destroy books.

Feature: Books

  Scenario: Searching for a book
    Given a book exists with a title of "Of Mice and Men"

If you feature is not tagged with @search the environment will use a sunspot test proxy object which will silently swallow all requests.

Starting solr will depend on your settings in config/sunspot.yml (though this configuration file is optional). If you run into issues remember to look for existing java processes, starting solr may conflict with existing instances. You can also check out which contains a little more information.

Can it do RSpec?

In spec_helper.rb

require 'sunspot_test/rspec'

Then within your specs, you'll need to tag and explicitly commit changes to solr:

require 'spec_helper'

describe "searching", :search => true do
  it 'returns book results' do
    book = Factory(:book, :title => "Of Mice and Men")
    Sunspot.commit { keywords "mice"}.results.should == [book]

Can it do TestUnit?

Same as RSpec.

In test_helper.rb

require 'sunspot_test/test_unit'

Then within your test, you'll need to tag and explicitly commit changes to solr:

test 'searching' do
  book = Factory(:book, :title => "Of Mice and Men")
  assert_equal [book], { keywords "mice"}.results

Configuring the timeout

The test suite will try and launch a solr process and wait for 15 seconds for the process to launch. You can configure this timeout by setting the following in env.rb:

SunspotTest.solr_startup_timeout = 60 # will wait 60 seconds for the solr process to start

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix. future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.


Copyright (c) 2011 Zach Moazeni. See LICENSE for details.

Something went wrong with that request. Please try again.