nio4r 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,20 @@
1
- require 'spec_helper'
2
- require 'openssl'
1
+ require "spec_helper"
2
+ require "openssl"
3
3
 
4
- describe OpenSSL::SSL::SSLSocket, :if => RUBY_VERSION >= "1.9.0" do
5
- let(:tcp_port) { 34567 }
4
+ RSpec.describe OpenSSL::SSL::SSLSocket, if: RUBY_VERSION >= "1.9.0" do
5
+ let(:tcp_port) { 34_567 }
6
6
 
7
7
  let(:ssl_key) { OpenSSL::PKey::RSA.new(1024) }
8
8
 
9
9
  let(:ssl_cert) do
10
- name = OpenSSL::X509::Name.new([%w[CN localhost]])
10
+ name = OpenSSL::X509::Name.new([%w(CN localhost)])
11
11
  OpenSSL::X509::Certificate.new.tap do |cert|
12
12
  cert.version = 2
13
13
  cert.serial = 1
14
14
  cert.issuer = name
15
15
  cert.subject = name
16
16
  cert.not_before = Time.now
17
- cert.not_after = Time.now + (365 * 24 *60 *60)
17
+ cert.not_after = Time.now + (365 * 24 * 60 * 60)
18
18
  cert.public_key = ssl_key.public_key
19
19
 
20
20
  cert.sign(ssl_key, OpenSSL::Digest::SHA1.new)
@@ -114,8 +114,8 @@ describe OpenSSL::SSL::SSLSocket, :if => RUBY_VERSION >= "1.9.0" do
114
114
  expect(count).not_to eq(0)
115
115
  rescue IO::WaitReadable, IO::WaitWritable
116
116
  pending "SSL will report writable but not accept writes"
117
- raise if(writers.include? ssl_client)
118
- end while writers and writers.include? ssl_client
117
+ raise if writers.include? ssl_client
118
+ end while writers && writers.include?(ssl_client)
119
119
 
120
120
  # I think the kernel might manage to drain its buffer a bit even after
121
121
  # the socket first goes unwritable. Attempt to sleep past this and then
@@ -124,15 +124,15 @@ describe OpenSSL::SSL::SSLSocket, :if => RUBY_VERSION >= "1.9.0" do
124
124
 
125
125
  # Once more for good measure!
126
126
  begin
127
- # ssl_client.write_nonblock "X" * 1024
127
+ # ssl_client.write_nonblock "X" * 1024
128
128
  loop { ssl_client.write_nonblock "X" * 1024 }
129
129
  rescue OpenSSL::SSL::SSLError
130
130
  end
131
131
 
132
132
  # Sanity check to make sure we actually produced an unwritable socket
133
- # if select([], [ssl_client], [], 0)
134
- # pending "Failed to produce an unwritable socket"
135
- # end
133
+ # if select([], [ssl_client], [], 0)
134
+ # pending "Failed to produce an unwritable socket"
135
+ # end
136
136
 
137
137
  ssl_client
138
138
  end
@@ -1,8 +1,8 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe TCPSocket do
3
+ RSpec.describe TCPSocket do
4
4
  port_offset = 0
5
- let(:tcp_port) { 12345 + (port_offset += 1) }
5
+ let(:tcp_port) { 12_345 + (port_offset += 1) }
6
6
 
7
7
  let :readable_subject do
8
8
  server = TCPServer.new("localhost", tcp_port)
@@ -37,7 +37,7 @@ describe TCPSocket do
37
37
  begin
38
38
  sock.write_nonblock "X" * 1024
39
39
  _, writers = select [], [sock], [], 0
40
- end while writers and writers.include? sock
40
+ end while writers && writers.include?(sock)
41
41
 
42
42
  # I think the kernel might manage to drain its buffer a bit even after
43
43
  # the socket first goes unwritable. Attempt to sleep past this and then
@@ -71,18 +71,18 @@ describe TCPSocket do
71
71
  context :connect do
72
72
  it "selects writable when connected" do
73
73
  selector = NIO::Selector.new
74
- server = TCPServer.new('127.0.0.1', tcp_port)
74
+ server = TCPServer.new("127.0.0.1", tcp_port)
75
75
 
76
76
  client = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
77
77
  monitor = selector.register(client, :w)
78
78
 
79
79
  expect do
80
- client.connect_nonblock Socket.sockaddr_in(tcp_port, '127.0.0.1')
80
+ client.connect_nonblock Socket.sockaddr_in(tcp_port, "127.0.0.1")
81
81
  end.to raise_exception Errno::EINPROGRESS
82
82
 
83
- expect(selector.select(0)).to include monitor
83
+ expect(selector.select(0.001)).to include monitor
84
84
  result = client.getsockopt(::Socket::SOL_SOCKET, ::Socket::SO_ERROR)
85
- expect(result.unpack('i').first).to be_zero
85
+ expect(result.unpack("i").first).to be_zero
86
86
  end
87
87
  end
88
88
  end
@@ -1,21 +1,21 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe UDPSocket do
4
- let(:udp_port) { 23456 }
3
+ RSpec.describe UDPSocket do
4
+ let(:udp_port) { 23_456 }
5
5
 
6
6
  let :readable_subject do
7
7
  sock = UDPSocket.new
8
- sock.bind('localhost', udp_port)
8
+ sock.bind("localhost", udp_port)
9
9
 
10
10
  peer = UDPSocket.new
11
- peer.send("hi there", 0, 'localhost', udp_port)
11
+ peer.send("hi there", 0, "localhost", udp_port)
12
12
 
13
13
  sock
14
14
  end
15
15
 
16
16
  let :unreadable_subject do
17
17
  sock = UDPSocket.new
18
- sock.bind('localhost', udp_port + 1)
18
+ sock.bind("localhost", udp_port + 1)
19
19
  sock
20
20
  end
21
21
 
@@ -1,11 +1,11 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  # Timeouts should be at least this precise (in seconds) to pass the tests
4
4
  # Typical precision should be better than this, but if it's worse it will fail
5
5
  # the tests
6
6
  TIMEOUT_PRECISION = 0.1
7
7
 
8
- describe NIO::Selector do
8
+ RSpec.describe NIO::Selector do
9
9
  let(:pair) { IO.pipe }
10
10
  let(:reader) { pair.first }
11
11
  let(:writer) { pair.last }
@@ -117,7 +117,7 @@ describe NIO::Selector do
117
117
  context "select" do
118
118
  it "selects IO objects" do
119
119
  writer << "ohai"
120
- unready, _ = IO.pipe
120
+ unready = IO.pipe.first
121
121
 
122
122
  reader_monitor = subject.register(reader, :r)
123
123
  unready_monitor = subject.register(unready, :r)
@@ -147,7 +147,7 @@ describe NIO::Selector do
147
147
  readable2, writer = IO.pipe
148
148
  writer << "ohai"
149
149
 
150
- unreadable, _ = IO.pipe
150
+ unreadable = IO.pipe.first
151
151
 
152
152
  monitor1 = subject.register(readable1, :r)
153
153
  monitor2 = subject.register(readable2, :r)
@@ -161,6 +161,12 @@ describe NIO::Selector do
161
161
  expect(readables).to include monitor2
162
162
  expect(readables).not_to include monitor3
163
163
  end
164
+
165
+ it "raises IOError if asked to select on a closed selector" do
166
+ subject.close
167
+
168
+ expect { subject.select(0) }.to raise_exception IOError
169
+ end
164
170
  end
165
171
 
166
172
  it "closes" do
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,9 @@
1
- require 'coveralls'
1
+ require "coveralls"
2
2
  Coveralls.wear!
3
3
 
4
- require 'rubygems'
5
- require 'bundler/setup'
6
- require 'nio'
7
- require 'support/selectable_examples'
4
+ require "rubygems"
5
+ require "bundler/setup"
6
+ require "nio"
7
+ require "support/selectable_examples"
8
+
9
+ RSpec.configure(&:disable_monkey_patching!)
@@ -1,4 +1,4 @@
1
- shared_context "an NIO selectable" do
1
+ RSpec.shared_context "an NIO selectable" do
2
2
  let(:selector) { NIO::Selector.new }
3
3
 
4
4
  it "selects readable objects" do
@@ -26,25 +26,25 @@ shared_context "an NIO selectable" do
26
26
  end
27
27
  end
28
28
 
29
- shared_context "an NIO selectable stream" do
29
+ RSpec.shared_context "an NIO selectable stream" do
30
30
  let(:selector) { NIO::Selector.new }
31
31
  let(:stream) { pair.first }
32
32
  let(:peer) { pair.last }
33
33
 
34
34
  it "selects readable when the other end closes" do
35
35
  # hax: this test is broken for OpenSSL sockets
36
- skip 'broken for SSL ;_;' if peer.is_a? OpenSSL::SSL::SSLSocket
36
+ skip "broken for SSL ;_;" if peer.is_a? OpenSSL::SSL::SSLSocket
37
37
 
38
38
  monitor = selector.register(stream, :r)
39
39
  expect(selector.select(0)).to be_nil
40
40
 
41
41
  peer.close
42
- #Wait and give the TCP session time to close
42
+ # Wait and give the TCP session time to close
43
43
  expect(selector.select(0.1)).to include monitor
44
44
  end
45
45
  end
46
46
 
47
- shared_context "an NIO bidirectional stream" do
47
+ RSpec.shared_context "an NIO bidirectional stream" do
48
48
  let(:selector) { NIO::Selector.new }
49
49
  let(:stream) { pair.first }
50
50
  let(:peer) { pair.last }
data/tasks/extension.rake CHANGED
@@ -1,11 +1,11 @@
1
1
  if defined? JRUBY_VERSION
2
- require 'rake/javaextensiontask'
3
- Rake::JavaExtensionTask.new('nio4r_ext') do |ext|
4
- ext.ext_dir = 'ext/nio4r'
2
+ require "rake/javaextensiontask"
3
+ Rake::JavaExtensionTask.new("nio4r_ext") do |ext|
4
+ ext.ext_dir = "ext/nio4r"
5
5
  end
6
6
  else
7
- require 'rake/extensiontask'
8
- Rake::ExtensionTask.new('nio4r_ext') do |ext|
9
- ext.ext_dir = 'ext/nio4r'
7
+ require "rake/extensiontask"
8
+ Rake::ExtensionTask.new("nio4r_ext") do |ext|
9
+ ext.ext_dir = "ext/nio4r"
10
10
  end
11
- end
11
+ end
data/tasks/rspec.rake CHANGED
@@ -1,7 +1,7 @@
1
- require 'rspec/core/rake_task'
1
+ require "rspec/core/rake_task"
2
2
 
3
3
  RSpec::Core::RakeTask.new
4
4
 
5
5
  RSpec::Core::RakeTask.new(:rcov) do |task|
6
- task.rcov = true
6
+ task.rcov = true
7
7
  end
@@ -0,0 +1,3 @@
1
+ require "rubocop/rake_task"
2
+
3
+ RuboCop::RakeTask.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nio4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-11 00:00:00.000000000 Z
11
+ date: 2015-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -44,14 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.0.0
47
+ version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.0.0
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: New IO for Ruby
56
70
  email:
57
71
  - tony.arcieri@gmail.com
@@ -62,6 +76,8 @@ extra_rdoc_files: []
62
76
  files:
63
77
  - ".gitignore"
64
78
  - ".rspec"
79
+ - ".rubocop.yml"
80
+ - ".rubocop_todo.yml"
65
81
  - ".travis.yml"
66
82
  - CHANGES.md
67
83
  - Gemfile
@@ -108,6 +124,7 @@ files:
108
124
  - spec/support/selectable_examples.rb
109
125
  - tasks/extension.rake
110
126
  - tasks/rspec.rake
127
+ - tasks/rubocop.rake
111
128
  homepage: https://github.com/celluloid/nio4r
112
129
  licenses:
113
130
  - MIT
@@ -128,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
145
  version: '0'
129
146
  requirements: []
130
147
  rubyforge_project:
131
- rubygems_version: 2.4.5
148
+ rubygems_version: 2.4.8
132
149
  signing_key:
133
150
  specification_version: 4
134
151
  summary: NIO provides a high performance selector API for monitoring IO objects
@@ -142,4 +159,3 @@ test_files:
142
159
  - spec/nio/selector_spec.rb
143
160
  - spec/spec_helper.rb
144
161
  - spec/support/selectable_examples.rb
145
- has_rdoc: