2

I hunted for this high and low, specifically for a RSpec rake task with both dependencies and task arguments - found answer and helping the future generations

Basically I want to do filter the tests by tag, and pass in a trigger I use for some app-specific behaviour.

bundle exec rake spec[some_tag,some_trigger]

And I wanted to depend on the :clean and 'test-reports' tasks

Leif
  • 1,129
  • 1
  • 12
  • 18

1 Answers1

5

The answer is in a comment documenting the 'resolve_args_with_dependencies(args, hash)' method in the lib/rake/task_manager.rb file.

# The patterns recognized by this argument resolving function are:
#
#   task :t => [:d]
#   task :t, [a] => [:d]

So this means you need to declare the task as follows

# :spec task depends on clean and 'test-reports' tasks
# and takes args for tags and triggers
RSpec::Core::RakeTask.new(:spec, [:tag, :triggers] => [:clean, 'test-reports']) do |task, args|
  task.rspec_opts = "--tag #{args[:tag]}"
  # args is a Rake::TaskArguments object (NOT a hash)
  ENV[TRIGGERS] = args[:triggers]
end
Leif
  • 1,129
  • 1
  • 12
  • 18
  • There is also a much longer discussion on this at http://stackoverflow.com/questions/825748/how-do-i-pass-command-line-arguments-to-a-rake-task?rq=1, but I didnt look there first cause there was no mention of dependencies in the title – Leif Dec 27 '15 at 00:47