2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
2017-10-28 11:15:48 -04:00
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
describe "Dir.empty?" do
|
|
|
|
before :all do
|
|
|
|
@empty_dir = tmp("empty_dir")
|
|
|
|
mkdir_p @empty_dir
|
|
|
|
end
|
2017-10-28 11:15:48 -04:00
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
after :all do
|
|
|
|
rm_r @empty_dir
|
|
|
|
end
|
2017-10-28 11:15:48 -04:00
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "returns true for empty directories" do
|
|
|
|
result = Dir.empty? @empty_dir
|
|
|
|
result.should be_true
|
|
|
|
end
|
2017-10-28 11:15:48 -04:00
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "returns false for non-empty directories" do
|
|
|
|
result = Dir.empty? __dir__
|
|
|
|
result.should be_false
|
|
|
|
end
|
2017-10-28 11:15:48 -04:00
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "returns false for a non-directory" do
|
|
|
|
result = Dir.empty? __FILE__
|
|
|
|
result.should be_false
|
|
|
|
end
|
2017-10-28 11:15:48 -04:00
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "raises ENOENT for nonexistent directories" do
|
|
|
|
lambda { Dir.empty? tmp("nonexistent") }.should raise_error(Errno::ENOENT)
|
2017-10-28 11:15:48 -04:00
|
|
|
end
|
|
|
|
end
|