Testing Your Rake Tasks
This is the second part of my previous post Improving our rake tasks.
In this one we will discuss a way for testing our
rake task, the example will be very straight forward.
We will invoke the
rake task and expect that some class
receive the correct arguments.
I will use Rspec as my test framework.
And I will continue with the same example from last post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
So the first we do is load
rake and we create a
before block which will be executed before every test.
We load in memory the
file where our tasks life, so rake will know what task to
execute. And we seat up the environment
after block took some time to figured out why, but I was geeting failing test because I was missing this one. Rake will store all the task that has been assigned, so the test where sharing the result, or so the expectation wasn’t met.
There is this great documentation for
Rake, I really encourage to look it Rake
Finally in our test we have to
invoke our task, to execute it and see what results are we getting.
Also point out because we previously refactor our
rake this test is really easy to implement.
I will continue this series of post with a more complete one, focus on testing.
Thanks for reading, any comments please don’t hesitate.