summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Williams <[email protected]>2025-01-29 01:20:08 +1300
committerGitHub <[email protected]>2025-01-29 01:20:08 +1300
commitd3abee739f4feb91bb9aaae33877d70c8c576db0 (patch)
tree22890c1afb714385665031405f1d2bf7f1c09d51
parentbaf22a057887ec9e3a03203f607029f2517ae758 (diff)
Add fallback for `hostname` if `uname` isn't available. (#12655)
Notes
Notes: Merged-By: ioquatix <[email protected]>
-rw-r--r--spec/ruby/library/socket/socket/gethostname_spec.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/spec/ruby/library/socket/socket/gethostname_spec.rb b/spec/ruby/library/socket/socket/gethostname_spec.rb
index bdc47dc611..89e1ed496f 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 '../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