Skip to content

Commit

Permalink
add hostname helper
Browse files Browse the repository at this point in the history
fixes platforms that are missing the hostname executable by
providing for an array of fallback commands that return
equivalent information
  • Loading branch information
Chuck Remes committed Feb 9, 2012
1 parent 295a670 commit 86d1b1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions mspec/lib/mspec/helpers/environment.rb
Expand Up @@ -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
6 changes: 3 additions & 3 deletions spec/ruby/library/socket/socket/gethostname_spec.rb
Expand Up @@ -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

1 comment on commit 86d1b1b

@jfirebaugh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a spec in mspec/spec for the helper?

Please sign in to comment.