Skip to content

Commit b8a240e

Browse files
committed
Fix specs for SystemError#message on Windows when errno value is not supported
1 parent 4aa40aa commit b8a240e

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

core/exception/system_call_error_spec.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,25 @@ def initialize
9696
end
9797

9898
it "sets an 'unknown error' message when an unknown error number" do
99-
SystemCallError.new(-1).message.should =~ /Unknown error(:)? -1/
99+
platform_is_not :windows do
100+
SystemCallError.new(-1).message.should =~ /Unknown error(:)? -1/
101+
end
102+
103+
platform_is :windows do
104+
SystemCallError.new(-1).message.should =~ "The operation completed successfully."
105+
SystemCallError.new(50).message.should =~ "Unknown Error"
106+
end
100107
end
101108

102109
it "adds a custom error message to an 'unknown error' message when an unknown error number and a custom message specified" do
103-
SystemCallError.new("custom message", -1).message.should =~ /Unknown error(:)? -1 - custom message/
110+
platform_is_not :windows do
111+
SystemCallError.new("custom message", -1).message.should =~ /Unknown error(:)? -1 - custom message/
112+
end
113+
114+
platform_is :windows do
115+
SystemCallError.new(-1).message.should =~ "The operation completed successfully. - custom message"
116+
SystemCallError.new(50).message.should =~ "Unknown Error - custom message"
117+
end
104118
end
105119

106120
it "converts to Integer if errno is a Complex convertible to Integer" do

optional/capi/kernel_spec.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,14 @@ class CApiKernelSpecs::Exc < StandardError
197197
end
198198

199199
it "uses an 'unknown error' message when errno is unknown" do
200-
-> do
201-
@s.rb_syserr_fail(-10, nil)
202-
end.should raise_error(SystemCallError, /Unknown error(:)? -1/) # a new class Errno::E-01 is generated on the fly
200+
platform_is_not :windows do
201+
-> { @s.rb_syserr_fail(-10, nil) }.should raise_error(SystemCallError, /Unknown error(:)? -10/)
202+
end
203+
204+
platform_is :windows do
205+
-> { @s.rb_syserr_fail(-1, nil) }.should raise_error(SystemCallError, "The operation completed successfully.")
206+
-> { @s.rb_syserr_fail(50, nil) }.should raise_error(SystemCallError, "Unknown Error")
207+
end
203208
end
204209
end
205210

@@ -217,9 +222,14 @@ class CApiKernelSpecs::Exc < StandardError
217222
end
218223

219224
it "uses an 'unknown error' message when errno is unknown" do
220-
-> do
221-
@s.rb_syserr_fail_str(-1, nil)
222-
end.should raise_error(SystemCallError, /Unknown error(:)? -1/) # a new class Errno::E-01 is generated on the fly
225+
platform_is_not :windows do
226+
-> { @s.rb_syserr_fail_str(-10, nil) }.should raise_error(SystemCallError, /Unknown error(:)? -10/)
227+
end
228+
229+
platform_is :windows do
230+
-> { @s.rb_syserr_fail_str(-1, nil) }.should raise_error(SystemCallError, "The operation completed successfully.")
231+
-> { @s.rb_syserr_fail_str(50, nil) }.should raise_error(SystemCallError, "Unknown Error")
232+
end
223233
end
224234
end
225235

0 commit comments

Comments
 (0)