Sha256: 4ece49e9b5cf94dc740fece2df4158a8151f52ea31178eec927db9799ded6a1a

Contents?: true

Size: 1.47 KB

Versions: 13

Compression:

Stored size: 1.47 KB

Contents

require File.expand_path('../spec_helper', __FILE__)

describe Cool.io::TimerWatcher do

  interval = 0.010

  it "can have the on_timer callback defined after creation" do
    @watcher = Cool.io::TimerWatcher.new(interval, true)
    nr = '0'
    @watcher.on_timer { nr.succ! }.should == nil
    @watcher.attach(Cool.io::Loop.default).should == @watcher
    nr.should == '0'
    sleep interval
    Cool.io::Loop.default.run_once
    nr.should == '1'
  end

  it "can be subclassed" do
    class MyTimerWatcher < Cool.io::TimerWatcher
      TMP = '0'

      def on_timer
        TMP.succ!
      end
    end
    @watcher = MyTimerWatcher.new(interval, true)
    @watcher.attach(Cool.io::Loop.default).should == @watcher
    MyTimerWatcher::TMP.should == '0'
    sleep interval
    Cool.io::Loop.default.run_once
    MyTimerWatcher::TMP.should == '1'
  end

  it "can have the on_timer callback redefined between runs" do
    @watcher = Cool.io::TimerWatcher.new(interval, true)
    nr = '0'
    @watcher.on_timer { nr.succ! }.should == nil
    @watcher.attach(Cool.io::Loop.default).should == @watcher
    nr.should == '0'
    sleep interval
    Cool.io::Loop.default.run_once
    nr.should == '1'
    @watcher.detach
    @watcher.on_timer { nr = :foo }.should == nil
    @watcher.attach(Cool.io::Loop.default).should == @watcher
    nr.should == '1'
    sleep interval
    Cool.io::Loop.default.run_once
    nr.should == :foo
  end

  after :each do
    @watcher.detach if defined?(@watcher)
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cool.io-1.3.0 spec/timer_watcher_spec.rb
cool.io-1.2.4 spec/timer_watcher_spec.rb
cool.io-1.2.3-x86-mingw32 spec/timer_watcher_spec.rb
cool.io-1.2.3 spec/timer_watcher_spec.rb
cool.io-1.2.2 spec/timer_watcher_spec.rb
cool.io-1.2.1 spec/timer_watcher_spec.rb
cool.io-1.1.1 spec/timer_watcher_spec.rb
cool.io-1.2.0-x86-mswin32-60 spec/timer_watcher_spec.rb
cool.io-1.2.0-x86-mingw32 spec/timer_watcher_spec.rb
cool.io-1.2.0 spec/timer_watcher_spec.rb
cool.io-1.1.0 spec/timer_watcher_spec.rb
cool.io-1.0.0 spec/timer_watcher_spec.rb
cool.io-0.9.0 spec/timer_watcher_spec.rb