Sha256: 26fa905d71c4280a06385fffa6dbcaa3bf6bd2cd4ea3775ff9d46ea891ddf3b3

Contents?: true

Size: 1.73 KB

Versions: 8

Compression:

Stored size: 1.73 KB

Contents

#
# Specifying rufus-scheduler
#
# Wed Apr 17 06:00:59 JST 2013
#

require 'spec_helper'


describe Rufus::Scheduler do

  before :each do
    @scheduler = Rufus::Scheduler.new
  end
  after :each do
    @scheduler.shutdown
  end

  describe '#every' do

    it 'adds a job' do

      @scheduler.every(10) do
      end

      @scheduler.jobs.size.should == 1
      @scheduler.jobs.first.class.should == Rufus::Scheduler::EveryJob
    end

    it 'triggers a job (2 times)' do

      counter = 0

      @scheduler.every(0.4) do
        counter += 1
      end

      sleep 2.0

      counter.should > 2
    end

    it 'does not remove the job after execution' do

      @scheduler.every(0.4) do
      end

      sleep 0.9

      @scheduler.jobs.size.should == 1
    end

    it 'raises on negative frequencies' do

      lambda {
        @scheduler.every(-1) do
        end
      }.should raise_error(ArgumentError)
    end

    it 'raises on zero frequencies' do

      lambda {
        @scheduler.every(0) do
        end
      }.should raise_error(ArgumentError)
    end

    it 'does not reschedule if the job was unscheduled' do

      counter = 0

      job =
        @scheduler.schedule_every '0.5s' do
          counter = counter + 1
        end

      sleep 1.6

      job.unschedule
      c = counter

      sleep 1.6

      counter.should == c
    end

    it 'raises if the job frequency is higher than the scheduler frequency' do

      @scheduler.frequency = 10

      lambda {
        @scheduler.every '1s' do; end
      }.should raise_error(ArgumentError)
    end
  end

  describe '#schedule_every' do

    it 'accepts a duration string' do

      job = @scheduler.schedule_every('1h') do; end

      job.frequency.should == 3600.0
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rufus-scheduler-3.0.7 spec/schedule_every_spec.rb
rufus-scheduler-3.0.6 spec/schedule_every_spec.rb
rufus-scheduler-3.0.5 spec/schedule_every_spec.rb
rufus-scheduler-3.0.4 spec/schedule_every_spec.rb
rufus-scheduler-3.0.3 spec/schedule_every_spec.rb
rufus-scheduler-3.0.2 spec/schedule_every_spec.rb
rufus-scheduler-3.0.1 spec/schedule_every_spec.rb
rufus-scheduler-3.0.0 spec/schedule_every_spec.rb