Use this as a Rake task prerequisite when we need to access project code (eg. entities, actions, views, etc..)

Imagine we want to build a Rake task that is able to access project code (eg. a repository)

  1. task clear_users: :environment do
  2. UserRepository.new.clear
  3. end

This is the default Rake task, which runs the test suite

  1. $ bundle exec rake

The (or :spec in case you generated the application with --test=rspec switch) Rake task is the default.

Many Software as a Service (SaaS) of the Ruby server hosting ecosystem are modeled after Ruby on Rails. For instance, Heroku expects to find the following Rake tasks in a Ruby application:

  • db:migrate

For Heroku, there isn’t a way to customize the deploy, so we’re supporting these “standard” Rake tasks from Ruby on Rails.

If you want to create a custom rake tasks you can create a folder in project root:

  1. $ mkdir rakelib/

And after that create *.rake file, export.rake for example:

Now you can see your custom rake task in the list:

  1. $ bundle exec rake -T
  2. rake export:books # Export books to algolia service
  3. rake spec # Run RSpec code examples