Default Rake Task

Default Rake Task

Published: Dec 29th, 2020

This is part of The Annotated Guide to a New Rails App, a list of recommendations to make developing your Rails app more productive and joyful.

In this article, we are talking about adding to the default rake task.

I recommend adding to the default rake task every time you add a tool that automatically checks your codebase.

Having a single command to run all of your automated checks and specs makes it easy to run them after every change and before every deploy.

First, create Rake tasks for automated checkers that do not have one.

In lib/tasks/rubocop.rake put

if Gem::Specification.find_all_by_name('rubocop').present?
require 'rubocop/rake_task'
RuboCop::RakeTask.new
end

Now you can run rake rubocop.

In lib/tasks/bundler_audit.rake put

if Gem::Specification.find_all_by_name('bundler-audit').present?
require 'bundler/audit/task'
Bundler::Audit::Task.new
end

Now you can run rake bundle:audit.

In lib/tasks/license_finder.rake put

task license_finder: :environment do
sh 'license_finder', '--quiet'
end

Now you can run rake license_finder.

In lib/tasks/rails_best_practices.rake put

task rails_best_practices: :environment do
sh 'rails_best_practices'
end

Now you can run rake rails_best_practices.

In lib/tasks/brakeman.rake put

if Gem::Specification.find_all_by_name('brakeman').present?
namespace :brakeman do
desc "Check your code with Brakeman"
task check: :environment do
require 'brakeman'
r = Brakeman.run app_path: '.', print_report: true, pager: false
exit Brakeman::Warnings_Found_Exit_Code unless r.filtered_warnings.empty?
end
end
end

Now you can run rake brakeman:check.

Edit your Rakefile define the default rake task.

task default: %i[
rubocop
spec
rails_best_practices
license_finder
brakeman:check
bundle:audit
]

To run the default task with all of your automated checks and specs use this command: rake.

--

--

--

Engineering leader with twenty years of experience in software startups

Love podcasts or audiobooks? Learn on the go with our new app.

Install Java on Ubuntu 18.04

Why you should have a Growth Mindset?

MY GIT NOTES…

Test SNS and SQS with LocalStack local development environment.

MPL Gaming Platform Goes from 0to 40 Million Users on AWS(Case-Study)

Open Banking — What should you know as an account holder?

RASA in AWS ECS…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Damien Burke

Damien Burke

Engineering leader with twenty years of experience in software startups

More from Medium

Setting Up Default Rails Controllers

💎 Ruby Radar #51 — RailsConf Wrap

Beginner’s guide to creating a command-line application in Ruby

A plant sprouting from a jar of money

Create a Feature in a Database Using SQLite3 and Active Record: Creating a Table