2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
|
|
|
require_relative 'fixtures/common'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "Dir.home" do
|
2018-12-29 19:05:56 -05:00
|
|
|
before :each do
|
|
|
|
@home = ENV['HOME']
|
|
|
|
ENV['HOME'] = "/rubyspec_home"
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2018-12-29 19:05:56 -05:00
|
|
|
after :each do
|
|
|
|
ENV['HOME'] = @home
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
2018-12-29 19:05:56 -05:00
|
|
|
describe "when called without arguments" do
|
|
|
|
it "returns the current user's home directory, reading $HOME first" do
|
|
|
|
Dir.home.should == "/rubyspec_home"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a non-frozen string" do
|
2020-05-03 06:28:29 -04:00
|
|
|
Dir.home.should_not.frozen?
|
2018-12-03 19:40:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-29 19:05:56 -05:00
|
|
|
describe "when called with the current user name" do
|
|
|
|
platform_is :solaris do
|
|
|
|
it "returns the named user's home directory from the user database" do
|
|
|
|
Dir.home(ENV['USER']).should == `getent passwd #{ENV['USER']}|cut -d: -f6`.chomp
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-25 03:17:47 -05:00
|
|
|
platform_is_not :windows, :solaris, :android, :wasi do
|
2018-12-29 19:05:56 -05:00
|
|
|
it "returns the named user's home directory, from the user database" do
|
|
|
|
Dir.home(ENV['USER']).should == `echo ~#{ENV['USER']}`.chomp
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a non-frozen string" do
|
2020-05-03 06:28:29 -04:00
|
|
|
Dir.home(ENV['USER']).should_not.frozen?
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an ArgumentError if the named user doesn't exist" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { Dir.home('geuw2n288dh2k') }.should raise_error(ArgumentError)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|