Allow pure Ruby and Java NIO::Selector to be initialized with nil

Trying to make this consistent across all backends. Passing nil was only
working with libev.
This commit is contained in:
Joao Fernandes 2021-01-04 18:38:38 +00:00 committed by Samuel Williams
parent 17155b9db7
commit 4111b1cee8
4 changed files with 8 additions and 2 deletions

View File

@ -43,7 +43,7 @@ public class Selector extends RubyObject {
@JRubyMethod
public IRubyObject initialize(ThreadContext context, IRubyObject backend) {
if(backend != context.runtime.newSymbol("java")) {
if(backend != context.runtime.newSymbol("java") && !backend.isNil()) {
throw context.runtime.newArgumentError(":java is the only supported backend");
}

View File

@ -14,7 +14,7 @@ module NIO
# Create a new NIO::Selector
def initialize(backend = :ruby)
raise ArgumentError, "unsupported backend: #{backend}" unless backend == :ruby
raise ArgumentError, "unsupported backend: #{backend}" unless [:ruby, nil].include?(backend)
@selectables = {}
@lock = Mutex.new

View File

@ -24,6 +24,10 @@ RSpec.describe NIO::Selector do
example.reporter.message "Supported backends: #{described_class.backends}"
end
it "automatically selects a backend if none or nil is specified" do
expect(described_class.new.backend).to eq described_class.new(nil).backend
end
it "raises ArgumentError if given an invalid backend" do
expect { described_class.new(:derp) }.to raise_error ArgumentError
end

View File

@ -12,6 +12,8 @@ RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
config.filter_run_when_matching :focus
config.expect_with :rspec do |c|
c.syntax = :expect
end