diff options
Diffstat (limited to 'spec/ruby/core/dir/exist_spec.rb')
| -rw-r--r-- | spec/ruby/core/dir/exist_spec.rb | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/spec/ruby/core/dir/exist_spec.rb b/spec/ruby/core/dir/exist_spec.rb index 43987b0f32..05ad67dd03 100644 --- a/spec/ruby/core/dir/exist_spec.rb +++ b/spec/ruby/core/dir/exist_spec.rb @@ -1,6 +1,5 @@ require_relative '../../spec_helper' require_relative 'fixtures/common' -require_relative 'shared/exist' describe "Dir.exist?" do before :all do @@ -11,5 +10,65 @@ describe "Dir.exist?" do DirSpecs.delete_mock_dirs end - it_behaves_like :dir_exist, :exist? + it "returns true if the given directory exists" do + Dir.exist?(__dir__).should == true + end + + it "returns true for '.'" do + Dir.exist?('.').should == true + end + + it "returns true for '..'" do + Dir.exist?('..').should == true + end + + it "understands non-ASCII paths" do + subdir = File.join(tmp("\u{9876}\u{665}")) + Dir.exist?(subdir).should == false + Dir.mkdir(subdir) + Dir.exist?(subdir).should == true + Dir.rmdir(subdir) + end + + it "understands relative paths" do + Dir.exist?(__dir__ + '/../').should == true + end + + it "returns false if the given directory doesn't exist" do + Dir.exist?('y26dg27n2nwjs8a/').should == false + end + + it "doesn't require the name to have a trailing slash" do + dir = __dir__ + dir.sub!(/\/$/,'') + Dir.exist?(dir).should == true + end + + it "doesn't expand paths" do + skip "$HOME not valid directory" unless ENV['HOME'] && File.directory?(ENV['HOME']) + Dir.exist?(File.expand_path('~')).should == true + Dir.exist?('~').should == false + end + + it "returns false if the argument exists but is a file" do + File.should.exist?(__FILE__) + Dir.exist?(__FILE__).should == false + end + + it "doesn't set $! when file doesn't exist" do + Dir.exist?("/path/to/non/existent/dir") + $!.should == nil + end + + it "calls #to_path on non String arguments" do + p = mock('path') + p.should_receive(:to_path).and_return(__dir__) + Dir.exist?(p) + end +end + +describe "Dir.exists?" do + it "has been removed" do + Dir.should_not.respond_to?(:exists?) + end end |
