1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 15:18:01 +00:00
Files
til/ruby/set-default-tasks-for-rake-to-run.md
2025-11-10 18:06:12 -06:00

1.2 KiB

Set Default Tasks For Rake To Run

Let's say our Ruby codebase has a test rake task and a test:system rake task. One runs our unit tests and the other runs our system (headless browser-based) tests. They aren't necessary defined in our Rakefile. In fact, that's how it is in a Rails codebase where these are defined by Rails itself.

We want the default action when rake is invoked by itself to be to run both of those test tasks.

This can be accomplished by specifying a default task and specifying both of those tasks as prerequisites.

task default: ["test", "test:system"]

The default task itself does nothing. When we invoke it though, it has to run our prerequisites. So running rake results in test and then test:system getting run.

If I have something like unicornleap or confetti, then I can have one of those run in the event that all the prerequisites pass.

task default: ["test", "test:system"] do
  system("unicornleap") if system("which unicornleap > /dev/null 2>&1")
end