Skip to content

Instantly share code, notes, and snippets.

@andrewhavens
Last active December 24, 2015 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewhavens/6784719 to your computer and use it in GitHub Desktop.
Save andrewhavens/6784719 to your computer and use it in GitHub Desktop.
Broken thinking sphinx rspec config
feature "Search for Models" do
let(:my_model){ FactoryGirl.create(:my_fancy_model) }
before do
ThinkingSphinx::Test.index
end
scenario "A user searches for models by title" do
visit "/models"
click_link("Advanced Search")
within("#adv_search") do
fill_in 'title', :with => my_model.title
click_link("Search")
end
page.should have_content(my_model.title)
end
end
# encoding: utf-8
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
require 'capybara/rails'
require 'thinking_sphinx/test'
require 'database_cleaner'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.include Capybara::DSL
config.include Capybara::RSpecMatchers
config.mock_with :rspec
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.strategy = :deletion
# Ensure sphinx directories exist for the test environment
ThinkingSphinx::Test.init
# Configure and start Sphinx, and automatically
# stop Sphinx at the end of the test suite.
ThinkingSphinx::Test.start_with_autostop
end
config.before(:each) do
DatabaseCleaner.start
# Index data when running an acceptance spec.
ThinkingSphinx::Test.index
end
config.after(:each) do
DatabaseCleaner.clean
end
config.include SphinxHelpers, type: :request
end
end
module SphinxHelpers
def index
ThinkingSphinx::Test.index
# Wait for Sphinx to finish loading in the new index files.
sleep 0.25 until index_finished?
end
def index_finished?
Dir[Rails.root.join(ThinkingSphinx::Test.config.searchd_file_path, '*.{new,tmp}.*')].empty?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment