From 79c470b815759a11fb18cce5665369ed16cbbcb9 Mon Sep 17 00:00:00 2001 From: Espartaco Palma Date: Sat, 7 Oct 2017 19:17:39 -0700 Subject: [PATCH 1/2] Adding Pathname#empty? specs Pathname#empty was added on MRI 2.4 --- library/pathname/empty_spec.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 library/pathname/empty_spec.rb diff --git a/library/pathname/empty_spec.rb b/library/pathname/empty_spec.rb new file mode 100644 index 0000000000..d18223ddc2 --- /dev/null +++ b/library/pathname/empty_spec.rb @@ -0,0 +1,28 @@ +require File.expand_path('../../spec_helper', __dir__) +require 'pathname' + +describe "Pathname#empty?" do + ruby_version_is "2.4" do + it 'returns true when file is not empty' do + (Pathname.new(__FILE__).empty?).should be_false + end + + it 'returns false when the directory is not empty' do + (Pathname.new(__dir__).empty?).should be_false + end + + it 'return true when file is empty' do + file = tmp('new_file_path_name.txt') + touch(file) + (Pathname.new(file).empty?).should be_true + File.delete(file) + end + + it 'returns true when directory is empty' do + dir = File.join(tmp("new_directory_path_name")) + Dir.mkdir(dir) + (Pathname.new(dir).empty?).should be_true + Dir.rmdir(dir) + end + end +end From 03f64841316e3ed35dc47874bd8c7f930a853329 Mon Sep 17 00:00:00 2001 From: Espartaco Palma Date: Sun, 8 Oct 2017 08:42:11 -0700 Subject: [PATCH 2/2] Changes on Pathname#empty? specs per Peer-Review --- library/pathname/empty_spec.rb | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/library/pathname/empty_spec.rb b/library/pathname/empty_spec.rb index d18223ddc2..ffe00c32e4 100644 --- a/library/pathname/empty_spec.rb +++ b/library/pathname/empty_spec.rb @@ -1,28 +1,34 @@ require File.expand_path('../../spec_helper', __dir__) require 'pathname' -describe "Pathname#empty?" do - ruby_version_is "2.4" do +ruby_version_is '2.4' do + describe 'Pathname#empty?' do + before :all do + @file = tmp 'new_file_path_name.txt' + touch @file + @dir = tmp 'new_directory_path_name' + Dir.mkdir @dir + end + + after :all do + rm_r @file + rm_r @dir + end + it 'returns true when file is not empty' do - (Pathname.new(__FILE__).empty?).should be_false + Pathname.new(__FILE__).empty?.should be_false end it 'returns false when the directory is not empty' do - (Pathname.new(__dir__).empty?).should be_false + Pathname.new(__dir__).empty?.should be_false end it 'return true when file is empty' do - file = tmp('new_file_path_name.txt') - touch(file) - (Pathname.new(file).empty?).should be_true - File.delete(file) + Pathname.new(@file).empty?.should be_true end it 'returns true when directory is empty' do - dir = File.join(tmp("new_directory_path_name")) - Dir.mkdir(dir) - (Pathname.new(dir).empty?).should be_true - Dir.rmdir(dir) + Pathname.new(@dir).empty?.should be_true end end end