Turnip Rake Task
Wouldn't it be nice if, when using the excellent turnip gem, rake
ran both your unit tests and your acceptance tests, just like your old cucumber setup?
First, let's define a task for running our acceptance tests. I threw it into lib/tasks/turnip.rake
:
desc 'Run turnip acceptance tests'
RSpec::Core::RakeTask.new(:turnip) do |t|
t.pattern = './spec{,/*/**}/*.feature'
t.rspec_opts = ['-r turnip/rspec']
end
Assuming you've got the rspec-rails
gem, you should already have a default task named spec
that runs your unit tests. Now all we need is to add our new task to that default task:
task :default => [:turnip]
Note that this will not override the default
task, it will only append this new dependency. For clarity, though, you might want to change it to say:
task :default => [:spec, :turnip]
Rake is clever enough to know to run the spec
task only once. Enjoy!
Written by Ryland Herrick
Related protips
2 Responses
This sounds interesting, but I'd like to have a spec:turnip
task, so I have done the following:
namespace :spec do
desc 'Run turnip acceptance tests'
RSpec::Core::RakeTask.new :turnip do |t|
t.pattern = './spec{,/*/**}/*.feature'
t.rspec_opts = ['-r turnip/rspec']
end
end
But now, how can I automatically let it be run when I do rake spec
?
@jmuheim, you can add dependencies to a task by 'redefining' that task with new dependencies:
task :spec => 'spec:turnip'