File: cancel_spec.rb

package info (click to toggle)
ruby-timers 4.1.1-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 196 kB
  • sloc: ruby: 668; makefile: 7
file content (46 lines) | stat: -rw-r--r-- 832 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

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