File: timeout_spec.rb

package info (click to toggle)
ruby-timers 4.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 200 kB
  • sloc: ruby: 668; makefile: 8
file content (29 lines) | stat: -rw-r--r-- 601 bytes parent folder | download | duplicates (3)
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

require 'spec_helper'
require 'timers/wait'

RSpec.describe Timers::Wait do
  it "repeats until timeout expired" do
    timeout = Timers::Wait.new(5)
    count = 0
    
    timeout.while_time_remaining do |remaining|
      expect(remaining).to be_within(TIMER_QUANTUM).of (timeout.duration - count)
      
      count += 1
      sleep 1
    end
    
    expect(count).to eq(5)
  end
  
  it "yields results as soon as possible" do
    timeout = Timers::Wait.new(5)
    
    result = timeout.while_time_remaining do |remaining|
      break :done
    end
    
    expect(result).to eq(:done)
  end
end