From bac1830534eff52d8d11cee5e4d038a34583e120 Mon Sep 17 00:00:00 2001 From: HeroProtagonist Date: Fri, 23 Oct 2020 00:06:10 -0400 Subject: [PATCH 1/5] Add specs for pathname.glob --- library/pathname/glob_spec.rb | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 library/pathname/glob_spec.rb diff --git a/library/pathname/glob_spec.rb b/library/pathname/glob_spec.rb new file mode 100644 index 0000000000..b920d6c4a5 --- /dev/null +++ b/library/pathname/glob_spec.rb @@ -0,0 +1,61 @@ +require_relative '../../spec_helper' +require 'pathname' + +describe 'Pathname#glob' do + before :all do + @dir = tmp '' + @file_1 = @dir + 'lib/ipaddr.rb' + @file_2 = @dir + 'lib/irb.rb' + @file_3 = @dir + 'lib/.hidden.rb' + + touch @file_1 + touch @file_2 + touch @file_3 + end + + after :all do + rm_r @dir + end + + it 'returns [] for no match' do + Pathname.glob(@dir + 'lib/*.js').should == [] + end + + it 'returns matching file paths' do + Pathname.glob(@dir + 'lib/*i*.rb').should == [Pathname.new(@file_1), Pathname.new(@file_2)] + end + + it 'returns matching file paths when a flag is provided' do + Pathname.glob(@dir + 'lib/*i*.rb', File::FNM_DOTMATCH).should == [Pathname.new(@file_1), Pathname.new(@file_2), Pathname.new(@file_3)] + end + + it 'returns matching file paths when supplied :base keyword argument' do + Pathname.glob('*i*.rb', base: @dir + 'lib').should == [Pathname.new('ipaddr.rb'), Pathname.new('irb.rb')] + end + + ruby_version_is ''...'2.7' do + it 'raises an ArgumentError when supplied a flag and :base keyword argument' do + -> { + Pathname.glob(@dir + 'lib/*i*.rb', File::FNM_DOTMATCH, base: 'lib') + }.should raise_error(ArgumentError, 'wrong number of arguments (given 3, expected 1..2)') + end + + it "raises an ArgumentError when supplied a keyword argument other than :base" do + -> { + Pathname.glob('*i*.rb', foo: @dir + 'lib') + }.should raise_error(ArgumentError, 'unknown keyword: foo') + end + end + + ruby_version_is "2.7"..."3.0" do + it "does not raise an ArgumentError when supplied a flag and :base keyword argument" do + Pathname.glob('*i*.rb', File::FNM_DOTMATCH, base: @dir + 'lib').should == [Pathname.new('ipaddr.rb'), Pathname.new('irb.rb'), Pathname.new('.hidden.rb')] + end + + it "raises an ArgumentError when supplied a keyword argument other than :base" do + -> { + Pathname.glob('*i*.rb', foo: @dir + 'lib') + }.should raise_error(ArgumentError, 'unknown keyword: :foo') + end + end +end From ff4aa7ba224388444a6b467de081ae1e9108de1c Mon Sep 17 00:00:00 2001 From: HeroProtagonist Date: Fri, 23 Oct 2020 00:16:32 -0400 Subject: [PATCH 2/5] Add sort for deterministic ordering --- library/pathname/glob_spec.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/library/pathname/glob_spec.rb b/library/pathname/glob_spec.rb index b920d6c4a5..b30a8b59ca 100644 --- a/library/pathname/glob_spec.rb +++ b/library/pathname/glob_spec.rb @@ -22,15 +22,16 @@ end it 'returns matching file paths' do - Pathname.glob(@dir + 'lib/*i*.rb').should == [Pathname.new(@file_1), Pathname.new(@file_2)] + Pathname.glob(@dir + 'lib/*i*.rb').sort.should == [Pathname.new(@file_1), Pathname.new(@file_2)].sort end it 'returns matching file paths when a flag is provided' do - Pathname.glob(@dir + 'lib/*i*.rb', File::FNM_DOTMATCH).should == [Pathname.new(@file_1), Pathname.new(@file_2), Pathname.new(@file_3)] + expected = [Pathname.new(@file_1), Pathname.new(@file_2), Pathname.new(@file_3)].sort + Pathname.glob(@dir + 'lib/*i*.rb', File::FNM_DOTMATCH).sort.should == expected end it 'returns matching file paths when supplied :base keyword argument' do - Pathname.glob('*i*.rb', base: @dir + 'lib').should == [Pathname.new('ipaddr.rb'), Pathname.new('irb.rb')] + Pathname.glob('*i*.rb', base: @dir + 'lib').sort.should == [Pathname.new('ipaddr.rb'), Pathname.new('irb.rb')].sort end ruby_version_is ''...'2.7' do @@ -49,7 +50,8 @@ ruby_version_is "2.7"..."3.0" do it "does not raise an ArgumentError when supplied a flag and :base keyword argument" do - Pathname.glob('*i*.rb', File::FNM_DOTMATCH, base: @dir + 'lib').should == [Pathname.new('ipaddr.rb'), Pathname.new('irb.rb'), Pathname.new('.hidden.rb')] + expected = [Pathname.new('ipaddr.rb'), Pathname.new('irb.rb'), Pathname.new('.hidden.rb')].sort + Pathname.glob('*i*.rb', File::FNM_DOTMATCH, base: @dir + 'lib').sort.should == expected end it "raises an ArgumentError when supplied a keyword argument other than :base" do From 5b4258ca4d14fe9b066cd477a3825fc3033ccb04 Mon Sep 17 00:00:00 2001 From: HeroProtagonist Date: Sat, 24 Oct 2020 13:40:13 -0400 Subject: [PATCH 3/5] Update ruby version for block --- library/pathname/glob_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/pathname/glob_spec.rb b/library/pathname/glob_spec.rb index b30a8b59ca..a138b5f328 100644 --- a/library/pathname/glob_spec.rb +++ b/library/pathname/glob_spec.rb @@ -48,7 +48,7 @@ end end - ruby_version_is "2.7"..."3.0" do + ruby_version_is "2.7" do it "does not raise an ArgumentError when supplied a flag and :base keyword argument" do expected = [Pathname.new('ipaddr.rb'), Pathname.new('irb.rb'), Pathname.new('.hidden.rb')].sort Pathname.glob('*i*.rb', File::FNM_DOTMATCH, base: @dir + 'lib').sort.should == expected From 5d82c37b8ea5b07b90a014a2192577744db185a9 Mon Sep 17 00:00:00 2001 From: HeroProtagonist Date: Sun, 25 Oct 2020 12:14:24 -0400 Subject: [PATCH 4/5] Use regex for unknown keyword error --- library/pathname/glob_spec.rb | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/library/pathname/glob_spec.rb b/library/pathname/glob_spec.rb index a138b5f328..4b35aca470 100644 --- a/library/pathname/glob_spec.rb +++ b/library/pathname/glob_spec.rb @@ -34,18 +34,18 @@ Pathname.glob('*i*.rb', base: @dir + 'lib').sort.should == [Pathname.new('ipaddr.rb'), Pathname.new('irb.rb')].sort end + it "raises an ArgumentError when supplied a keyword argument other than :base" do + -> { + Pathname.glob('*i*.rb', foo: @dir + 'lib') + }.should raise_error(ArgumentError, /unknown keyword: :?foo/) + end + ruby_version_is ''...'2.7' do it 'raises an ArgumentError when supplied a flag and :base keyword argument' do -> { Pathname.glob(@dir + 'lib/*i*.rb', File::FNM_DOTMATCH, base: 'lib') }.should raise_error(ArgumentError, 'wrong number of arguments (given 3, expected 1..2)') end - - it "raises an ArgumentError when supplied a keyword argument other than :base" do - -> { - Pathname.glob('*i*.rb', foo: @dir + 'lib') - }.should raise_error(ArgumentError, 'unknown keyword: foo') - end end ruby_version_is "2.7" do @@ -53,11 +53,5 @@ expected = [Pathname.new('ipaddr.rb'), Pathname.new('irb.rb'), Pathname.new('.hidden.rb')].sort Pathname.glob('*i*.rb', File::FNM_DOTMATCH, base: @dir + 'lib').sort.should == expected end - - it "raises an ArgumentError when supplied a keyword argument other than :base" do - -> { - Pathname.glob('*i*.rb', foo: @dir + 'lib') - }.should raise_error(ArgumentError, 'unknown keyword: :foo') - end end end From 92f02b53ea92aba01e46755d272f6ac6ffd530ba Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 26 Oct 2020 08:12:31 +0100 Subject: [PATCH 5/5] Use its own directory for Pathname#glob specs --- library/pathname/glob_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/pathname/glob_spec.rb b/library/pathname/glob_spec.rb index 4b35aca470..5904858d2d 100644 --- a/library/pathname/glob_spec.rb +++ b/library/pathname/glob_spec.rb @@ -3,7 +3,7 @@ describe 'Pathname#glob' do before :all do - @dir = tmp '' + @dir = tmp 'pathname_glob' @file_1 = @dir + 'lib/ipaddr.rb' @file_2 = @dir + 'lib/irb.rb' @file_3 = @dir + 'lib/.hidden.rb'