Sha256: 3afad5e5b27ed0851f7ba807ef16bd73e65d7f6de7e68d48fd4229c97fe1fa19

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

describe Nanoc::ChangesStream do
  let(:simple_stream) do
    described_class.new do |cl|
      cl.unknown
      sleep
    end
  end

  it 'returns a stream of events generated by the listener' do
    buffered_stream = DDBuffer.new(1).call(simple_stream)
    expect(buffered_stream.take(1).to_a).to eq([:unknown])
  end

  describe '#map' do
    it 'returns a new maped enum' do
      stream = simple_stream.map { |e| e.to_s.upcase }
      buffered_stream = DDBuffer.new(1).call(stream)
      expect(buffered_stream.take(1).to_a).to eq(['UNKNOWN'])
    end
  end

  describe '#to_enum' do
    it 'returns an enumerator corresponding to itself' do
      buffered_stream = DDBuffer.new(1).call(simple_stream.to_enum)
      expect(buffered_stream.take(1).to_a).to eq([:unknown])
    end
  end

  describe '#stop' do
    let(:simple_stream) do
      described_class.new do |cl|
        cl.to_stop { $changes_stream_stopped = true }
        sleep
      end
    end

    example do
      DDBuffer.new(1).call(simple_stream)
      sleep 0.1
      expect { simple_stream.stop }.to change { $changes_stream_stopped }.from(nil).to(true)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nanoc-4.8.12 spec/nanoc/base/changes_stream_spec.rb
nanoc-4.8.11 spec/nanoc/base/changes_stream_spec.rb