diff --git a/README.md b/README.md index 5a658d9..cd31e9e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1684 TILs and counting..._ +_1685 TILs and counting..._ See some of the other learning resources I work on: @@ -1436,6 +1436,7 @@ If you've learned something here, support my efforts writing daily TILs by - [Scripting With RVM](ruby/scripting-with-rvm.md) - [Scroll To Top Of Page With Capybara](ruby/scroll-to-top-of-page-with-capybara.md) - [Search For Gem Versions Available To Install](ruby/search-for-gem-versions-available-to-install.md) +- [Set Default Tasks For Rake To Run](ruby/set-default-tasks-for-rake-to-run.md) - [Set RVM Default Ruby](ruby/set-rvm-default-ruby.md) - [Shift The Month On A Date Object](ruby/shift-the-month-on-a-date-object.md) - [Show Public Methods With Pry](ruby/show-public-methods-with-pry.md) diff --git a/ruby/set-default-tasks-for-rake-to-run.md b/ruby/set-default-tasks-for-rake-to-run.md new file mode 100644 index 0000000..712df91 --- /dev/null +++ b/ruby/set-default-tasks-for-rake-to-run.md @@ -0,0 +1,32 @@ +# 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`](https://ruby.github.io/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. + +```ruby +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`](https://github.com/dkarter/dotfiles/blob/b5aae6a9edd5766f0cc9100235b0955a9d53aa85/installer/mac-setup.sh#L47-L74) +or +[`confetti`](https://manual.raycast.com/deeplinks#block-702a9613bc82440d853492f553876a20), +then I can have one of those run in the event that all the prerequisites pass. + +```ruby +task default: ["test", "test:system"] do + system("unicornleap") if system("which unicornleap > /dev/null 2>&1") +end +```