Sha256: 1f6c1c4cfefa20c790038bdf112047cb82cce1a2d8e3aed47fcdcc014439d8d9

Contents?: true

Size: 1001 Bytes

Versions: 4

Compression:

Stored size: 1001 Bytes

Contents

require 'spec_helper'

describe Pubsubstub::Channel do
  subject { described_class.new('foobar') }

  it "has a name" do
    expect(subject.name).to be == 'foobar'
  end

  it "has a scrollback key derived from the name" do
    expect(subject.scrollback_key).to be == 'foobar.scrollback'
  end

  it "has a pubsub key derived from the name" do
    expect(subject.pubsub_key).to be == 'foobar.pubsub'
  end

  describe "#publish" do
    let(:event) { Pubsubstub::Event.new("refresh #1", id: 1) }

    it "records the event in the scrollback" do
      expect {
        subject.publish(event)
      }.to change { subject.scrollback(since: 0) }.from([]).to([event])
    end
  end

  describe "#scrollback" do
    before do
      10.times do |i|
        subject.publish(Pubsubstub::Event.new("refresh ##{i}", id: i))
      end
    end

    it "returns the events with an id greater than the `since` parameter" do
      expect(subject.scrollback(since: 5).map(&:id)).to be == [6, 7, 8, 9]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pubsubstub-0.1.2 spec/channel_spec.rb
pubsubstub-0.1.1 spec/channel_spec.rb
pubsubstub-0.1.0 spec/channel_spec.rb
pubsubstub-0.1.0.beta1 spec/channel_spec.rb