File: acceptables_spec.rb

package info (click to toggle)
ruby-nio4r 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 528 kB
  • ctags: 1,100
  • sloc: ansic: 5,635; ruby: 679; java: 348; makefile: 5
file content (32 lines) | stat: -rw-r--r-- 811 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
require 'spec_helper'

describe "NIO acceptables" do
  shared_context "an NIO acceptable" do
    let(:selector) { NIO::Selector.new }

    it "selects for read readiness" do
      waiting_monitor = selector.register(unacceptable_subject, :r)
      ready_monitor   = selector.register(acceptable_subject, :r)

      ready_monitors = selector.select
      ready_monitors.should include ready_monitor
      ready_monitors.should_not include waiting_monitor
    end
  end

  describe TCPServer do
    let(:tcp_port) { 23456 }

    let :acceptable_subject do
      server = TCPServer.new("localhost", tcp_port)
      TCPSocket.open("localhost", tcp_port)
      server
    end

    let :unacceptable_subject do
      TCPServer.new("localhost", tcp_port + 1)
    end

    it_behaves_like "an NIO acceptable"
  end
end