diff options
Diffstat (limited to 'spec/ruby/core/dir/shared/glob.rb')
-rw-r--r-- | spec/ruby/core/dir/shared/glob.rb | 94 |
1 files changed, 46 insertions, 48 deletions
diff --git a/spec/ruby/core/dir/shared/glob.rb b/spec/ruby/core/dir/shared/glob.rb index b47e23b41c..0fcfcc4eea 100644 --- a/spec/ruby/core/dir/shared/glob.rb +++ b/spec/ruby/core/dir/shared/glob.rb @@ -291,74 +291,72 @@ describe :dir_glob, shared: true do end end - ruby_version_is "2.5" do - context ":base option passed" do - before :each do - @mock_dir = File.expand_path tmp('dir_glob_mock') + context ":base option passed" do + before :each do + @mock_dir = File.expand_path tmp('dir_glob_mock') - %w[ + %w[ a/b/x a/b/c/y a/b/c/d/z ].each do |path| - file = File.join @mock_dir, path - mkdir_p File.dirname(file) - touch file - end + file = File.join @mock_dir, path + mkdir_p File.dirname(file) + touch file end + end - after :each do - rm_r @mock_dir - end + after :each do + rm_r @mock_dir + end - it "matches entries only from within the specified directory" do - path = File.join(@mock_dir, "a/b/c") - Dir.send(@method, "*", base: path).sort.should == %w( d y ) - end + it "matches entries only from within the specified directory" do + path = File.join(@mock_dir, "a/b/c") + Dir.send(@method, "*", base: path).sort.should == %w( d y ) + end - it "accepts both relative and absolute paths" do - require 'pathname' + it "accepts both relative and absolute paths" do + require 'pathname' - path_abs = File.join(@mock_dir, "a/b/c") - path_rel = Pathname.new(path_abs).relative_path_from(Pathname.new(Dir.pwd)) + path_abs = File.join(@mock_dir, "a/b/c") + path_rel = Pathname.new(path_abs).relative_path_from(Pathname.new(Dir.pwd)) - result_abs = Dir.send(@method, "*", base: path_abs).sort - result_rel = Dir.send(@method, "*", base: path_rel).sort + result_abs = Dir.send(@method, "*", base: path_abs).sort + result_rel = Dir.send(@method, "*", base: path_rel).sort - result_abs.should == %w( d y ) - result_rel.should == %w( d y ) - end + result_abs.should == %w( d y ) + result_rel.should == %w( d y ) + end - it "returns [] if specified path does not exist" do - path = File.join(@mock_dir, "fake-name") - File.should_not.exist?(path) + it "returns [] if specified path does not exist" do + path = File.join(@mock_dir, "fake-name") + File.should_not.exist?(path) - Dir.send(@method, "*", base: path).should == [] - end + Dir.send(@method, "*", base: path).should == [] + end - it "returns [] if specified path is a file" do - path = File.join(@mock_dir, "a/b/x") - File.should.exist?(path) + it "returns [] if specified path is a file" do + path = File.join(@mock_dir, "a/b/x") + File.should.exist?(path) - Dir.send(@method, "*", base: path).should == [] - end + Dir.send(@method, "*", base: path).should == [] + end - it "raises TypeError when cannot convert value to string" do - -> { - Dir.send(@method, "*", base: []) - }.should raise_error(TypeError) - end + it "raises TypeError when cannot convert value to string" do + -> { + Dir.send(@method, "*", base: []) + }.should raise_error(TypeError) + end - it "handles '' as current directory path" do - Dir.chdir @mock_dir do - Dir.send(@method, "*", base: "").should == %w( a ) - end + it "handles '' as current directory path" do + Dir.chdir @mock_dir do + Dir.send(@method, "*", base: "").should == %w( a ) end + end - it "handles nil as current directory path" do - Dir.chdir @mock_dir do - Dir.send(@method, "*", base: nil).should == %w( a ) - end + it "handles nil as current directory path" do + Dir.chdir @mock_dir do + Dir.send(@method, "*", base: nil).should == %w( a ) end end end |