Separating the Steak
Posted in Uncategorized on June 23rd, 2010 by Marcelo de Moraes Serpa – Be the first to commentSteak is a great lightweight replacement for Cucumber. I’m not going to dig into it here since it’s not the point of this post, but suffice to say it is basically rSpec for acceptance/integration tests (aka features in the Cucumber world, whatever you prefer).
I’ve been having some issues with Steak though. The default Steak generator creates the infra-structure under spec/. At first sight, it doesn ‘t seem that bad, after all, acceptance tests are just specs with added sugar, right? Well, not really.
Even though Steak acceptance tests are just rSpec at its core, the nature of it make them a different beast. First, you often need to use Culerity with them. This also brings the need to use DatabaseCleaner. If you keep all of this under spec/, the rake spec task will load and run it all, including the DatabaseCleaner configuration, wreaking havoc with your rSpec unit-tests. Also, you often don’t want to run acceptance tests when running the suite of unit-tests, acceptance/integration tests are often much slower.
I’ve already opened an issue here on Steak’s github issues page. However, if you want to fix it now, here’s what you need to do.
1) First, move the acceptance directory out of spec/. I recommend moving it to the application’s top-level directory (RAILS_ROOT);
2) Now, open acceptance/acceptance_helper.rb and correct the require for spec_helper. If you’ve put the acceptance directory on RAILS_ROOT, the require should look like this:
"require File.dirname(__FILE__) + "/../spec/spec_helper"
3) Open lib/tasks/steak.rake, and correct all the references to the acceptance directory, again, if you’ve put on RAILS_ROOT, you just remove the “spec/” part on the path string. It would look like:
nless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
require 'spec/rake/spectask'
ENV['RAILS_ENV'] = 'development'
namespace :spec do
desc "Run the code examples in spec/acceptance"
Spec::Rake::SpecTask.new(:acceptance => "db:test:prepare") do |t|
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
t.spec_files = FileList["acceptance/**/*_spec.rb"]
end
# Setup stats to include acceptance specs
task :statsetup do
require 'code_statistics'
::STATS_DIRECTORIES << %w(Acceptance\ specs spec/acceptance) if File.exist?('acceptance')
::CodeStatistics::TEST_TYPES << "Acceptance specs" if File.exist?('acceptance')
end
end
end
Now you can run "rake spec:acceptance" for Steak acceptance tests, and "rake spec" for the rest of unit-tests.
