A couple of weeks ago, I was working on a task that required me to create a rake task. The rake task was supposed to be run in two different ways, one without any arguments and the other with an argument. I wrote the rake task and it was time to write the tests. I wrote the test for the rake task without any arguments and it passed. I then wrote the test for the rake task with an argument and it failed. It failed in a way that the task was not being run at all. I was confused.

After searching on the internet, I found out that the rake task was not being run because the task was already executed in the first test and it wasn’t possible to execute it again before reenabling the task.

after do
  Rake::Task['my_rake_task'].reenable
end

This is how I was able to test the same rake task multiple times. I hope this helps you too.

Newer post

How to handle dynamic text with String Catalogs

Using String Catalogs is a new way to localize your app, but how do you handle dynamic text?