I summarized the procedure of the RSpec test in this article.
Since I summarized it as simple as possible, please read through those who are trying to create Rake task for the first time.
😎 Creating a Rake task file
The following command creates a Rake task file in lib/tasks
:
(Please change “report”.)
$ rails generate task report |
Please write the following code in the above lib/tasks/report.rake
:
namespace :report do |
After the coding, you can execute rake report:generate
command!
🐯 RSpec for rake task
Executing rake task in RSpec
require 'rails_helper' |
Executing model method
namespace :report |
It’s so simple to execute unit testing.
In addition, if you type ReportGenerator.generate on rails console, you can also perform exactly the same processing as the Rake task.
🗽 Special Thanks
🖥 Recommended VPS Service
VULTR provides high performance cloud compute environment for you.
Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour).
In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!