Sha256: d9622e91b3ebaeaff97c0b38e2d2e0f2e9192ae7e361ca36c13ed44cd3846184

Contents?: true

Size: 1.67 KB

Versions: 5

Compression:

Stored size: 1.67 KB

Contents

#
# Specifying rufus-scheduler
#
# Mon May  4 17:07:17 JST 2009
#

require 'spec_base'


describe SCHEDULER_CLASS do

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

  it 'emits exception messages to stderr' do

    require 'stringio' unless defined?(StringIO) # ruby 1.9

    stderr = $stderr
    s = StringIO.new
    $stderr = s

    @s.in 0.400 do
      raise 'Houston we have a problem'
    end

    sleep 0.500
    sleep 0.500
    $stderr = stderr
    s.close

    s.string.should match(/Houston we have a problem/)
  end

  it 'accepts custom handling of exceptions' do

    $job = nil

    def @s.handle_exception(j, e)
      $job = j
    end

    @s.in 0.400 do
      raise 'Houston we have a problem'
    end

    sleep 0.500
    sleep 0.500

    $job.class.should == Rufus::Scheduler::InJob
  end

  it 'accepts defining #log_exception' do

    $e = nil

    def @s.log_exception(e)
      $e = e
    end

    @s.in 0.400 do
      raise 'Houston we have a problem'
    end

    sleep 0.500
    sleep 0.500

    $e.to_s.should == 'Houston we have a problem'
  end

  it 'accepts defining #on_exception' do

    $j = nil
    $e = nil

    def @s.on_exception(j, e)
      $j = j
      $e = e
    end

    @s.in 0.400 do
      raise 'Houston we have a problem'
    end

    sleep 0.500
    sleep 0.500

    $j.class.should == Rufus::Scheduler::InJob
    $e.to_s.should == 'Houston we have a problem'
  end

  it 'allow custom exception rescue' do
    @s.options[:exception]= StandardError

    job = @s.in 0 do
      exit
    end

    @e= nil
    begin
      wait_next_tick
    rescue SystemExit => e
      @e= e
    end

    @e.should_not == nil
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rufus-scheduler-2.0.24 spec/exception_spec.rb
rufus-scheduler-2.0.23 spec/exception_spec.rb
rufus-scheduler-2.0.22 spec/exception_spec.rb
rufus-scheduler-2.0.21 spec/exception_spec.rb
rufus-scheduler-2.0.20 spec/exception_spec.rb