Do you test your rake tasks?
I think that many of you think that writing tests for custom rake tasks is a redundant thing. But as practice shows if you think so you are wrong. In this post I will show how to test custom rake tasks.
Assuming that we have rake task for example products:load, and you can run it from the terminal by the following command:
At first glance you could test it manually on running
spec, or you could configure default rake which runs rspec and this rake task.
But 1st approach has side effect - your rake task will always populate database with products in this case, we don’t want to do it, we just want to make sure that rake works.
2nd approach looks like more robust, but if you use default rake task for other things it’s definitely not your choice. I prefer to test rakes by rspec.
Check out rspec test below:
MyApp::Application is a my application name, you can get it from
I hope this code doesn’t require deeper explanation and other lines of code are clear for you.
WideFix and Ruby On Rails expertise
At WideFix, we take pride in our expertise and experience. You can trust that our solutions will not harm your business and will always keep your site running smoothly. You can rely on us to provide confident and effective solutions that meet your needs.