Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support TestUnit #6

Merged
merged 1 commit into from
Sep 13, 2011
Merged

Added support TestUnit #6

merged 1 commit into from
Sep 13, 2011

Conversation

ordinaryzelig
Copy link
Contributor

Since it's so easy, might as well add support for TestUnit.

@ordinaryzelig
Copy link
Contributor Author

Could also send a pull request to https://github.com/sunspot/sunspot to add this gem to the Help and Support, Tutorials and Articles section. This seems to be a cleaner solution than the article they list about testing with TestUnit by Type Slowly, which is how I found this gem in the first place.

danielmorrison added a commit that referenced this pull request Sep 13, 2011
@danielmorrison danielmorrison merged commit 5e53990 into collectiveidea:master Sep 13, 2011
@@ -0,0 +1,4 @@
SunspotTest.stub
SunspotTest.setup_solr
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry for commenting on this one so so very late, but this will spin up solr on every startup, which can be really a nuisance when you want to run single tests that do not use solr.

I also find it confusing to have SunspotTest.stub, just to be contradicted right the next line with #setup_solr that unstubs the session.

My approach nowadays is:

# test_helper.rb

require "sunspot_test"
SunspotTest.stub

# since Test::Unit doesn't have the privileges of tags, I use a simple helper:

class ActiveSupport::TestCase # or MiniTest::Unit::TestCase or Test::Unit::TestCase

  def with_sunspot
    SunspotTest.setup_solr
    Sunspot.remove_all!
    Sunspot.commit
    yield
    SunspotTest.stub
  end

end

in my tests I make simple usage of it:

test "search works" do
  with_sunspot do
    create_model_records_that_will_be_indexed
    Model.search # works as expected
  end
end

test "this does not use search" do
  create_model_records_that_will_not_be_indexed
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants