Last Updated: February 25, 2016·
Thoughts on testing Rake tasks in Rails
Rake tasks are traditionally a pain to test. Josh from Thoughtbot has a wonderful article walking you through the process here: http://robots.thoughtbot.com/post/11957424161/test-rake-tasks-like-a-boss
After reading the article and following his example to test my own rake tasks I came to the conclusion that when testing rake tasks they should work like integration tests. Put all of your functionality in a model or class then unit test that class. Within your actual rake task you should just check to see if the methods are being called on the given classes with something like "describedclass.shouldreceive(:foo)" This will make your rake tasks both easier to maintain and test.
I'll update this with examples soon.
Written by Sterling Cobb
A better BDD/TDD
Testing on Android Studio
Have a fresh tip? Share with Coderwall community!
Post a tip
Best #Tdd Authors
Sponsored by #native_company# — Learn More