Auto-starts solr for your tests
Latest commit 43de58c Sep 29, 2016 @gaffneyc gaffneyc Merge branch 'pr/23'
Closes #23
Failed to load latest commit information.
features/support Adding initial code May 18, 2011
lib Merge branch 'pr/23' Sep 29, 2016
spec Consider a 503 response as Solr not running Sep 29, 2016
.travis.yml Update Travis config. Add ruby 2.2 and 2.3. Use latest 2.x. Sep 29, 2016
Gemfile Add code climate coverage Mar 29, 2014
Rakefile Remove jeweler and clean up gemspec Mar 29, 2014
sunspot_test.gemspec Update dependencies to the latest versions. Sep 29, 2016


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.