Rails:在开发环境中测试Cron Jobs

时间:2013-04-08 21:42:14

标签: ruby-on-rails ruby cron whenever

我有一个名为'reports'的自定义环境,设置为命中从属数据库。我正在尝试使用Whenever gem配置一些cron作业,并希望在部署之前在开发中测试它们。有没有办法在开发中测试cron作业?无论如何我可以在本地安排它们然后启动我的报告服务器,看看它们是否运行?谢谢!

1 个答案:

答案 0 :(得分:3)

我首先回顾一下宝石本身(每当宝石)如何进行测试。这是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
相关问题