Sha256: 7c2c504a51f921c6f9c2863fe87a10a9775a3e628f0c09f297a70d9dc34d11a9

Contents?: true

Size: 832 Bytes

Versions: 6

Compression:

Stored size: 832 Bytes

Contents

require 'spec_helper'

RSpec.describe Timers::Group do
  it "should be able to cancel twice" do
    fired = false

    timer = subject.after(0.1) { fired = true }
    
    2.times do
      timer.cancel
      subject.wait
    end

    expect(fired).to be false
  end
  
  it "should be possble to reset after cancel" do
    fired = false
    
    timer = subject.after(0.1) { fired = true }
    timer.cancel
    
    subject.wait
    
    timer.reset
    
    subject.wait
    
    expect(fired).to be true
  end
  
  it "should cancel and remove one shot timers after they fire" do
    x = 0

    Timers::Wait.for(2) do |remaining|
      timer = subject.every(0.2) { x += 1 }
      subject.after(0.1) { timer.cancel }
      
      subject.wait
    end
    
    expect(subject.timers).to be_empty
    expect(x).to be == 0
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
timers-4.0.4 spec/cancel_spec.rb
timers-4.1.1 spec/cancel_spec.rb
timers-4.1.0 spec/cancel_spec.rb
scoot-0.0.4 .bundle/gems/ruby/2.2.0/gems/timers-4.0.1/spec/cancel_spec.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/timers-4.0.1/spec/cancel_spec.rb
timers-4.0.1 spec/cancel_spec.rb