diff --git a/mspec/lib/mspec/helpers/environment.rb b/mspec/lib/mspec/helpers/environment.rb index 61ce365104..856dbf0484 100644 --- a/mspec/lib/mspec/helpers/environment.rb +++ b/mspec/lib/mspec/helpers/environment.rb @@ -37,4 +37,13 @@ def dev_null "/dev/null" end end + + def hostname + commands = ['hostname', 'uname -n'] + commands.each do |command| + name = `#{command}` + return name.strip if $?.success? + end + raise Exception, "hostname: unable to find a working command" + end end diff --git a/spec/ruby/library/socket/socket/gethostname_spec.rb b/spec/ruby/library/socket/socket/gethostname_spec.rb index f1255e249d..74122a2dba 100644 --- a/spec/ruby/library/socket/socket/gethostname_spec.rb +++ b/spec/ruby/library/socket/socket/gethostname_spec.rb @@ -2,9 +2,9 @@ require File.expand_path('../../fixtures/classes', __FILE__) describe "Socket.gethostname" do - # This currently works in Unix and Windows. Feel free to add guards - # for other platforms. + # This currently works in Unix and Windows. Edit the helper + # to add other platforms. it "returns the host name" do - Socket.gethostname.should == `hostname`.strip + Socket.gethostname.should == hostname end end