Sha256: 0985dbf1bb46c54f72ec0caac27d895e908dade4d185c538368a143cd6a0f4d7

Contents?: true

Size: 1.49 KB

Versions: 10

Compression:

Stored size: 1.49 KB

Contents

require 'spec_helper'

describe NIO::Monitor do
  let(:pipes) { IO.pipe }
  let(:reader) { pipes.first }
  let(:writer) { pipes.last }
  let(:selector) { NIO::Selector.new }

  subject    { selector.register(reader, :r) }
  let(:peer) { selector.register(writer, :rw) }
  after      { selector.close }

  it "knows its interests" do
    subject.interests.should == :r
    peer.interests.should == :rw
  end

  it "knows its IO object" do
    subject.io.should == reader
  end

  it "knows its selector" do
    subject.selector.should == selector
  end

  it "stores arbitrary values" do
    subject.value = 42
    subject.value.should == 42
  end

  it "knows what operations IO objects are ready for" do
    # For whatever odd reason this breaks unless we eagerly evaluate subject
    reader_monitor, writer_monitor = subject, peer

    selected = selector.select(0)
    selected.should_not include(reader_monitor)
    selected.should include(writer_monitor)

    writer_monitor.readiness.should == :w
    writer_monitor.should_not be_readable
    writer_monitor.should be_writable

    writer << "loldata"

    selected = selector.select(0)
    selected.should include(reader_monitor)

    reader_monitor.readiness.should == :r
    reader_monitor.should be_readable
    reader_monitor.should_not be_writable
  end

  it "closes" do
    subject.should_not be_closed
    selector.registered?(reader).should be_true

    subject.close
    subject.should be_closed
    selector.registered?(reader).should be_false
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
nio4r-1.0.0-java spec/nio/monitor_spec.rb
nio4r-1.0.0 spec/nio/monitor_spec.rb
nio4r-0.5.0-java spec/nio/monitor_spec.rb
nio4r-0.5.0 spec/nio/monitor_spec.rb
nio4r-0.4.6-java spec/nio/monitor_spec.rb
nio4r-0.4.6 spec/nio/monitor_spec.rb
nio4r-0.4.5-java spec/nio/monitor_spec.rb
nio4r-0.4.5 spec/nio/monitor_spec.rb
nio4r-0.4.4-java spec/nio/monitor_spec.rb
nio4r-0.4.4 spec/nio/monitor_spec.rb