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)
task clear_users: :environment do
UserRepository.new.clear
end
This is the default Rake task, which runs the test suite
$ 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:
$ mkdir rakelib/
And after that create *.rake
file, export.rake
for example:
Now you can see your custom rake task in the list:
$ bundle exec rake -T
rake export:books # Export books to algolia service
rake spec # Run RSpec code examples