dwfb4w
Last Updated: February 25, 2016
·
2.112K
· rylnd
Ff5dffecc90f6636461855fb52057609

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!

Say Thanks
Respond

2 Responses
Add your response

11859
34289b48cdb8d086793e8361b2d26de2

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?

over 1 year ago ·
11869
Ff5dffecc90f6636461855fb52057609

@jmuheim, you can add dependencies to a task by 'redefining' that task with new dependencies:

task :spec => 'spec:turnip'
over 1 year ago ·