Recently Cucumber added support for tagging features and scenarios which allows you to flexibly organise and categorise your features.
We've been able to use these tags to speed up our tests, quite considerably in some places. Once of our projects is using Sphinx (with the brilliant Thinking Sphinx), to search the database. As Cucumber tests the full stack, in order to get accurate test results we need to configure, index and start Sphinx before running the test suite.
Using tags, we need to only start up Sphinx if the features have been tagged "@sphinx". Whilst this doesn't give us any speed improvements when running the whole test suite, it does give measurably better results (in the order of 10 - 15 seconds on my machine) when only running a single test which doesn't need Sphinx.
# Cucumber::Rails::World.use_transactional_fixtures
Before do
DatabaseCleaner.clean
end
def sphinx_task(task)
%x{RAILS_ENV=test `which rake` ts:#{task}}
end
Before('@sphinx') do
unless ThinkingSphinx.sphinx_running?
sphinx_task(:config)
sphinx_task(:index)
sphinx_task(:run)
end
end
at_exit do
DatabaseCleaner.clean
if ThinkingSphinx.sphinx_running?
sphinx_task(:stop)
end
end
As an aside, it is important to note, that because we are using Sphinx we need to disable transactional fixtures for the indexing to work properly. There is the excellent database_cleaner gem which can wipe your database between steps, which you can see above.
