Sha256: 5d9290f5f95811db5bf7428476a143cf97ce729a432a6067999fdaff704a4f40

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

#
# Specifying rufus-scheduler
#
# Sun Mar 22 19:59:12 JST 2009
#

require File.join(File.dirname(__FILE__), 'spec_base')


describe "#{SCHEDULER_CLASS}#cron" do

  before(:each) do
    @s = start_scheduler
  end
  after(:each) do
    stop_scheduler(@s)
  end

  it 'has job ids with the class name in it' do

    j0 = @s.cron('7 10-12 * * * *') {}
    j0.job_id.should match(/Rufus::Scheduler::CronJob/)
  end

  it 'crons every second' do

    seconds = []

    job = @s.cron '* * * * * *'  do |job|
      seconds << job.last.sec
    end
    sleep 4.990

    job.unschedule

    seconds.uniq.size.should == seconds.size
  end

  it 'unschedules' do

    second = nil

    job = @s.cron '* * * * * *'  do |job|
      second = job.last.sec
    end

    second.should == nil

    sleep 2

    second.should_not == nil

    job.unschedule

    after = second

    sleep 2

    second.should == after
  end

  it 'keeps track of cron jobs' do

    j0 = @s.cron '7 10-12 * * * *' do
    end
    j1 = @s.cron '7 10-12 * * * *' do
    end

    @s.cron_jobs.keys.sort.should == [ j0.job_id, j1.job_id ].sort
  end

  it 'accepts tags for jobs' do

    job = @s.cron '* * * * * *', :tags => 'spec' do
    end

    wait_next_tick

    @s.find_by_tag('spec').size.should == 1
    @s.find_by_tag('spec').first.job_id.should == job.job_id
  end

  it 'accepts job.unschedule within the job' do

    stack = []

    @s.cron '* * * * * *' do |job|
      if stack.size > 2
        stack << 'done'
        job.unschedule
      else
        stack << 'ok'
      end
    end

    sleep 4

    @s.jobs.size.should == 0
    stack.should == %w[ ok ok ok done ]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rufus-scheduler-2.0.11 spec/cron_spec.rb
rufus-scheduler-2.0.10 spec/cron_spec.rb