I am using Capybara with Cucumber in my rails application. I want to run the Sphinx reindex and the Redis server to be running for some specific Test Scenarios. But the downside here is the scenarios are very very slow making it run for hours.
Here is my env.rb file
require 'rubygems'
ENV["RAILS_ENV"] = "cucumber"
require 'cucumber/rails'
require 'capybara/cucumber'
require 'capybara/rails'
require 'capybara/session'
require 'rake'
Capybara.default_selector = :css
ActionController::Base.allow_rescue = false
Cucumber::Rails::World.use_transactional_fixtures = true
Capybara.default_wait_time = 4
Capybara.ignore_hidden_elements=false
Capybara::Server.new(Capybara.app).boot
include Rake::DSL
Rake::Task["db:fixtures:load"].invoke
Before('@javascript') do
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app,:browser=>:chrome )
end
Capybara.current_driver = :selenium
Capybara.javascript_driver=:selenium
end
Before('@javascript', '@index') do
`rake ts:in RAILS_ENV=cucumber` unless ThinkingSphinx.sphinx_running?
`rake ts:start RAILS_ENV=cucumber`
end
After('@javascript','@index') do
`rake ts:stop RAILS_ENV=cucumber`
end
Before('@javascript','@redis','@javascript') do
`redis-server config/test_redis.conf`
`rake redis_specifics:cache_build RAILS_ENV=cucumber --trace`
end
After('@javascript','@redis','@javascript') do
pid = `ps aux | grep 'config/test_redis.conf'| grep -v 'grep' | awk '{print $2}'`
`pkill #{pid}`
end
One more problem is when I run this on different machines, there is a dependency that Redis is installed and that the user is having permission to create and destroy folders. Is there a better way to handle this situation? May be to implement the similar transactional style fixtures that the Normal testing framework of Rails uses ?
Any help is greatly appreciated.
I’d suggest using a library like fakeredis (https://github.com/guilleiguaran/fakeredis). This will get rid of the dependency on redis in your tests, and ensure that data is not kept around between tests.
I’d expect there to be something similar for sphinx, but don’t know of anything off the top of my head.