Skip to content

Commit

Permalink
Fix specs for SystemError#message on Windows when errno value is not …
Browse files Browse the repository at this point in the history
…supported
  • Loading branch information
andrykonchin committed Dec 9, 2024
1 parent 4aa40aa commit 5f6459f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
16 changes: 14 additions & 2 deletions core/exception/system_call_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,23 @@ def initialize
end

it "sets an 'unknown error' message when an unknown error number" do
SystemCallError.new(-1).message.should =~ /Unknown error(:)? -1/
platform_is_not :windows do
SystemCallError.new(-1).message.should =~ /Unknown error(:)? -1/
end

platform_is :windows do
SystemCallError.new(-1).message.should == "The operation completed successfully."
end
end

it "adds a custom error message to an 'unknown error' message when an unknown error number and a custom message specified" do
SystemCallError.new("custom message", -1).message.should =~ /Unknown error(:)? -1 - custom message/
platform_is_not :windows do
SystemCallError.new("custom message", -1).message.should =~ /Unknown error(:)? -1 - custom message/
end

platform_is :windows do
SystemCallError.new(-1).message.should == "The operation completed successfully. - custom message"
end
end

it "converts to Integer if errno is a Complex convertible to Integer" do
Expand Down
20 changes: 14 additions & 6 deletions optional/capi/kernel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,13 @@ class CApiKernelSpecs::Exc < StandardError
end

it "uses an 'unknown error' message when errno is unknown" do
-> do
@s.rb_syserr_fail(-10, nil)
end.should raise_error(SystemCallError, /Unknown error(:)? -1/) # a new class Errno::E-01 is generated on the fly
platform_is_not :windows do
-> { @s.rb_syserr_fail(-10, nil) }.should raise_error(SystemCallError, /Unknown error(:)? -10/)
end

platform_is :windows do
-> { @s.rb_syserr_fail(-1, nil) }.should raise_error(SystemCallError, "The operation completed successfully.")
end
end
end

Expand All @@ -217,9 +221,13 @@ class CApiKernelSpecs::Exc < StandardError
end

it "uses an 'unknown error' message when errno is unknown" do
-> do
@s.rb_syserr_fail_str(-1, nil)
end.should raise_error(SystemCallError, /Unknown error(:)? -1/) # a new class Errno::E-01 is generated on the fly
platform_is_not :windows do
-> { @s.rb_syserr_fail_str(-10, nil) }.should raise_error(SystemCallError, /Unknown error(:)? -10/)
end

platform_is :windows do
-> { @s.rb_syserr_fail_str(-1, nil) }.should raise_error(SystemCallError, "The operation completed successfully.")
end
end
end

Expand Down

0 comments on commit 5f6459f

Please sign in to comment.