File: timer_spec.rb

package info (click to toggle)
ruby-tty-prompt 0.23.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,452 kB
  • sloc: ruby: 8,847; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 611 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
# frozen_string_literal: true

RSpec.describe TTY::Prompt::Timer do
  it "times out loop execution" do
    timer = TTY::Prompt::Timer.new(0.03, 0.01)
    yielded = []

    timer.while_remaining do |remaining|
      expect(remaining).to be_within(0.1).of(timer.duration - yielded.size * 0.01)
      yielded << remaining
      sleep(0.01)
    end
  end

  it "registers a tick event" do
    timer = TTY::Prompt::Timer.new(0.03, 0.01)
    yielded = []

    timer.on_tick do |time|
      yielded << time
    end

    timer.while_remaining do
      # busy work
    end

    expect(yielded.size).to be >= 2
  end
end