Sha256: 12dd9e8feeafe6f881d0a385591caab41a9c22f7d61199b322cfe525b8e98656

Contents?: true

Size: 1.11 KB

Versions: 24

Compression:

Stored size: 1.11 KB

Contents

require 'spec_helper'

describe Rearview::CronHelper do

  context "next_valid_time_after" do
    before do
      now = Time.now
      Timecop.freeze(Time.local(now.year,now.mon,now.day))
    end

    after do
      Timecop.return
    end

    it "should calculate the correct delay for '0 * * * * ?'" do
      cron_expr = "0 * * * * ?"
      expect( Rearview::CronHelper.next_valid_time_after(cron_expr) ).to eq(60.0)
    end

    it "should calculate the correct delay for '0 30 * * * ?'" do
      cron_expr = "0 30 * * * ?"
      expect( Rearview::CronHelper.next_valid_time_after(cron_expr) ).to eq( 30 * 60 )
    end

    it "should calculate the correct delay for '0 0 13 * * ?'" do
      cron_expr = "0 0 13 * * ?"
      expect( Rearview::CronHelper.next_valid_time_after(cron_expr) ).to eq( 13 * 60 * 60 )
    end

  end

  context "valid_expression?" do
    it "should reject invalid expressions" do
      expect(Rearview::CronHelper.valid_expression?("nope")).to be_false
    end
    it "should accept valid expressions" do
      expect(Rearview::CronHelper.valid_expression?("0 * * * * ?")).to be_true
    end
  end

end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
rearview-1.2.3-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.2.2.rc.2-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.2.2.rc.1-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.2.1-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.2.0-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.1.2-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.1.1-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.1.0-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.0.3.rc.4-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.0.3.rc.3-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.0.3.rc.2-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.0.3.rc.1-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.0.2-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.0.2.rc.4-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.0.2.rc.3-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.0.2.rc.2-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.0.2.rc.1-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.0.1-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.0.0-jruby spec/lib/rearview/cron_helper_spec.rb
rearview-1.0.0.rc5-jruby spec/lib/rearview/cron_helper_spec.rb