File: ring_buffer_spec.rb

package info (click to toggle)
ruby-celluloid 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 848 kB
  • sloc: ruby: 7,579; makefile: 10
file content (36 lines) | stat: -rw-r--r-- 848 bytes parent folder | download
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
RSpec.describe Celluloid::RingBuffer do
  subject { Celluloid::RingBuffer.new(2) }

  it { is_expected.to be_empty }
  it { is_expected.not_to be_full }

  it "should push and shift" do
    subject.push("foo")
    subject.push("foo2")
    expect(subject.shift).to eq("foo")
    expect(subject.shift).to eq("foo2")
  end

  it "should push past the end" do
    subject.push("foo")
    subject.push("foo2")
    subject.push("foo3")
    expect(subject).to be_full
  end

  it "should shift the most recent" do
    (1..5).each { |i| subject.push(i) }
    expect(subject.shift).to be 4
    expect(subject.shift).to be 5
    expect(subject.shift).to be_nil
  end

  it "should return nil when shifting empty" do
    expect(subject).to be_empty
    expect(subject.shift).to be_nil
  end

  it "should be thread-safe" do
    # TODO: how to test?
  end
end