Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b97eec986fd5
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7e099e346734
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Nov 27, 2014

  1. Added specs for subclassing eg Errno::EMFILE.

    Pure crazy town, I know. Thanks, rack!.
    brixen committed Nov 27, 2014
    Copy the full SHA
    448bf43 View commit details
  2. Copy the full SHA
    7e099e3 View commit details
Showing with 46 additions and 4 deletions.
  1. +20 −2 kernel/common/exception.rb
  2. +8 −0 spec/ruby/core/exception/errno_spec.rb
  3. +18 −2 spec/ruby/core/exception/system_call_error_spec.rb
22 changes: 20 additions & 2 deletions kernel/common/exception.rb
Original file line number Diff line number Diff line change
@@ -371,7 +371,17 @@ def self.errno_error(message, errno)
# We use .new here because when errno is set, we attempt to
# lookup and return a subclass of SystemCallError, specificly,
# one of the Errno subclasses.
def self.new(message=undefined, errno=undefined)
def self.new(*args)
case args.size
when 0
message = errno = undefined
when 1
message = args.first
errno = undefined
else
message, errno = args
end

# This method is used 2 completely different ways. One is when it's called
# on SystemCallError, in which case it tries to construct a Errno subclass
# or makes a generic instead of itself.
@@ -414,7 +424,15 @@ def self.new(message=undefined, errno=undefined)
message = StringValue(message)
end

if error = SystemCallError.errno_error(message, self::Errno)
if self::Errno.kind_of? Fixnum
error = SystemCallError.errno_error(message, self::Errno)
else
error = allocate
end

if error
Rubinius::Unsafe.set_class error, self
Rubinius.privately { error.initialize(*args) }
return error
end

8 changes: 8 additions & 0 deletions spec/ruby/core/exception/errno_spec.rb
Original file line number Diff line number Diff line change
@@ -4,6 +4,14 @@
it "needs to be reviewed for spec completeness"
end

describe "Errno::EMFILE" do
it "can be subclassed" do
ExceptionSpecs::EMFILESub = Class.new(Errno::EMFILE)
exc = ExceptionSpecs::EMFILESub.new
exc.should be_an_instance_of(ExceptionSpecs::EMFILESub)
end
end

describe "Errno::EAGAIN" do
# From http://jira.codehaus.org/browse/JRUBY-4747
it "is the same class as Errno::EWOULDBLOCK if they represent the same errno value" do
20 changes: 18 additions & 2 deletions spec/ruby/core/exception/system_call_error_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
require File.expand_path('../../../spec_helper', __FILE__)

describe "SystemCallError" do
before :each do
ScratchPad.clear
end

it "can be subclassed" do
ExceptionSpecs::SCESub = Class.new(SystemCallError) do
def initialize
ScratchPad.record :initialize
end
end

exc = ExceptionSpecs::SCESub.new
ScratchPad.recorded.should equal(:initialize)
exc.should be_an_instance_of(ExceptionSpecs::SCESub)
end
end

describe "SystemCallError.new" do
it "requires at least one argumentt" do
lambda { SystemCallError.new }.should raise_error(ArgumentError)
@@ -54,5 +72,3 @@
SystemCallError.new("XXX").message.should =~ /XXX/
end
end