0.07
No commit activity in last 3 years
No release in over 3 years
Testing sunspot with cucumber can be a pain. This gem will automatically start/stop solr with cucumber scenarios tagged with @search
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

SunspotTest

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.

@search
Feature: Books

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

If your 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 http://collectiveidea.com/blog/archives/2011/05/25/testing-with-sunspot-and-cucumber/ 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
    Book.search { keywords "mice"}.results.should == [book]
  end
end

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")
  Sunspot.commit
  assert_equal [book], Book.search { keywords "mice"}.results
end

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

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