From 0da2b12741b2645f5c34f7e98e3b3b0f8f3cde5e Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Sat, 1 Feb 2025 00:28:35 +1300 Subject: [PATCH] Prefer `platform_is_not :windows`. --- spec/ruby/library/socket/socket/gethostname_spec.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spec/ruby/library/socket/socket/gethostname_spec.rb b/spec/ruby/library/socket/socket/gethostname_spec.rb index 89e1ed496f..dfca7cf5cd 100644 --- a/spec/ruby/library/socket/socket/gethostname_spec.rb +++ b/spec/ruby/library/socket/socket/gethostname_spec.rb @@ -3,11 +3,13 @@ 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 + if platform_is_not :windows + # `uname -n` is the most portable way to get the hostname, as it is a POSIX standard: + `uname -n`.strip + else + # Windows does not have uname, so we use hostname instead: + `hostname`.strip + end end it "returns the host name" do