Giter Club home page Giter Club logo

sunspot_test's Introduction

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 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 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.

sunspot_test's People

Contributors

zmoazeni avatar ersatzryan avatar danielmorrison avatar aaronjensen avatar daniel-g avatar ordinaryzelig avatar mattscilipoti avatar

Watchers

Satish Gunnu avatar James Cloos avatar  avatar  avatar  avatar Sudhakar Nallam avatar  avatar  avatar Lindsay Cordero avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.