Add fallback for hostname if uname isn't available. (#12655)

This commit is contained in:
Samuel Williams 2025-01-29 01:20:08 +13:00 committed by GitHub
parent baf22a0578
commit d3abee739f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2025-01-28 12:20:26 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>

View File

@ -2,7 +2,15 @@ require_relative '../spec_helper'
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