From d3abee739f4feb91bb9aaae33877d70c8c576db0 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Wed, 29 Jan 2025 01:20:08 +1300 Subject: [PATCH] Add fallback for `hostname` if `uname` isn't available. (#12655) --- spec/ruby/library/socket/socket/gethostname_spec.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/ruby/library/socket/socket/gethostname_spec.rb b/spec/ruby/library/socket/socket/gethostname_spec.rb index bdc47dc611a622..89e1ed496f10b0 100644 --- a/spec/ruby/library/socket/socket/gethostname_spec.rb +++ b/spec/ruby/library/socket/socket/gethostname_spec.rb @@ -2,7 +2,15 @@ require_relative '../fixtures/classes' describe "Socket.gethostname" do + def system_hostname + # Most platforms implement this POSIX standard: + `uname -n`.strip + rescue + # Only really required for Windows without MSYS/MinGW/Cygwin etc: + `hostname`.strip + end + it "returns the host name" do - Socket.gethostname.should == `uname -n`.strip + Socket.gethostname.should == system_hostname end end