Search code examples
rubyrufus-scheduler

Rufus Scheduler: specs for schedules?


I have just added the rufus scheduler gem to my application and ran it for a few minutes in development mode to find that it works.

But of course I'd like to write a spec that ensures the schedules are set up correctly. For example, typos could slip into the interval strings or some other gremlin might prevent.

My initial idea was to look at Scheduler#jobs but that can become tricky quite quickly: if there are, for example, two jobs with the same interval, I cannot see a straightforward way to identify the one to test.

Apart from that, it should be possible to set up some expectations, run the block and check whether the expected methods were called.

Do you have recommendations on how to test for correctness of job schedules at a given point in the application lifecycle?


Solution

  • You can place tags on jobs:

    https://github.com/jmettraux/rufus-scheduler#tags

    It helps identifying them. It's also useful to look them up:

    https://github.com/jmettraux/rufus-scheduler#schedulerjobstag--tags--x