From 891a3ecde570b2a0f327f99d13114ad3439c865a Mon Sep 17 00:00:00 2001 From: Espartaco Palma Date: Sat, 7 Oct 2017 17:50:41 -0700 Subject: [PATCH] Add spec for Dir.empty? Dir.empty? was added on MRI 2.4 --- core/dir/empty_spec.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 core/dir/empty_spec.rb diff --git a/core/dir/empty_spec.rb b/core/dir/empty_spec.rb new file mode 100644 index 0000000000..d1eb387a7a --- /dev/null +++ b/core/dir/empty_spec.rb @@ -0,0 +1,27 @@ +require File.expand_path('../../spec_helper', __dir__) +require File.expand_path('fixtures/common', __dir__) + +describe 'Dir.empty?' do + ruby_version_is "2.4" do + it 'Report false when the directory has a file(s)' do + (Dir.empty? __dir__).should be_false + end + + it 'Report false when path is not a folder' do + (Dir.empty? __FILE__).should be_false + end + + it 'Report true when the dir has no files' do + subdir = File.join(tmp("new_empty_folder_99")) + Dir.mkdir(subdir) + (Dir.empty? subdir).should be_true + Dir.rmdir(subdir) + end + + it 'Raise Errno::ENOENT on non-existing directory' do + lambda do + Dir.empty? DirSpecs.nonexistent + end.should raise_error(Errno::ENOENT) + end + end +end