timecop icon indicating copy to clipboard operation
timecop copied to clipboard

How to work with whenever gem?

Open mirelon opened this issue 8 years ago • 1 comments

Whenever is a gem for running scheduled jobs.

It supports definitions of jobs like this:

every 1.day, :at => '4:30 am' do
  runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
end

When I use Timecop.travel 1.day in a test, I would expect scheduled jobs to run. (not the one definned in crontab after running wheneverize, just the ruby code in schedule.rb)

What solution do you propose?

mirelon avatar Oct 27 '17 10:10 mirelon

whenever works simply by acting as a ruby DSL to generate a crontab.

  • The code above does not "run" as you describe. That's simply not how it works. Only the crontab is run.
  • In order to test the code in the manner you describe, you'd need to (1) generate the crontab, and then (2) update the system clock to be at a new time (e.g. 1 day ahead).
  • It would only make sense to perform such a test at an end-to-end level, regardless. This is not something you should be doing with Timecop. (Or, quite likely, at all. Why not just explicitly re-trigger MyModel.task_to_run_at_four_thirty_in_the_morning within the test?)

tom-lord avatar Dec 05 '17 22:12 tom-lord