diff options
Diffstat (limited to 'spec/ruby/core/dir/pwd_spec.rb')
| -rw-r--r-- | spec/ruby/core/dir/pwd_spec.rb | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/spec/ruby/core/dir/pwd_spec.rb b/spec/ruby/core/dir/pwd_spec.rb index 4fa86dd6b9..70208b03d6 100644 --- a/spec/ruby/core/dir/pwd_spec.rb +++ b/spec/ruby/core/dir/pwd_spec.rb @@ -1,7 +1,6 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/common', __FILE__) -require File.expand_path('../shared/pwd', __FILE__) +require_relative '../../spec_helper' +require_relative 'fixtures/common' describe "Dir.pwd" do before :all do @@ -12,7 +11,49 @@ describe "Dir.pwd" do DirSpecs.delete_mock_dirs end - it_behaves_like :dir_pwd, :pwd + before :each do + @fs_encoding = Encoding.find('filesystem') + end + + it "returns the current working directory" do + pwd = Dir.pwd + + File.directory?(pwd).should == true + + # On ubuntu gutsy, for example, /bin/pwd does not + # understand -P. With just `pwd -P`, /bin/pwd is run. + + # The following uses inode rather than file names to account for + # case insensitive file systems like default OS/X file systems + platform_is_not :windows do + File.stat(pwd).ino.should == File.stat(`/bin/sh -c "pwd -P"`.chomp).ino + end + platform_is :windows do + File.stat(pwd).ino.should == File.stat(File.expand_path(`cd`.chomp)).ino + end + end + + it "returns an absolute path" do + pwd = Dir.pwd + pwd.should == File.expand_path(pwd) + end + + it "returns an absolute path even when chdir to a relative path" do + Dir.chdir(".") do + pwd = Dir.pwd + File.directory?(pwd).should == true + pwd.should == File.expand_path(pwd) + end + end + + it "returns a String with the filesystem encoding" do + enc = Dir.pwd.encoding + if @fs_encoding == Encoding::US_ASCII + [Encoding::US_ASCII, Encoding::BINARY].should.include?(enc) + else + enc.should.equal?(@fs_encoding) + end + end end describe "Dir.pwd" do |
