Rails: Testing Cron in the Development Environment

I have a custom environment called “reports” that is configured to get into the production database. I am trying to configure some cron jobs with Whenever gem and want to test them in development before deployment. Is there a way to test cron work in development? In any case, I could schedule them locally and then start the report server and see if they are running? Thank!

+5
source share
1 answer

I would start by looking at how the stone itself ( whenever gem ) conducts its tests. This is an excerpt from one of their functional test :

context "weekday at a (single) given time" do
    setup do
      @output = Whenever.cron \
      <<-file
        set :job_template, nil
        every "weekday", :at => '5:02am' do
          command "blahblah"
        end
      file
    end

    should "output the command using that time" do
      assert_match '2 5 * * 1-5 blahblah', @output
    end
  end
+3
source

All Articles