diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-02-08 19:43:27 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-04-01 15:36:20 +0900 |
commit | 826f44834fe11f3f9c52343443a15b6c83466889 (patch) | |
tree | f2c2abed62db1c750515cd8b0fbac6442b6d4200 /spec/ruby/core/dir | |
parent | 3a2073e61b6ccce6d07d31ebd89d4c385b9a55f2 (diff) |
Drop support for ruby 2.4 from ruby/spec
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2892
Diffstat (limited to 'spec/ruby/core/dir')
-rw-r--r-- | spec/ruby/core/dir/children_spec.rb | 102 | ||||
-rw-r--r-- | spec/ruby/core/dir/each_child_spec.rb | 70 | ||||
-rw-r--r-- | spec/ruby/core/dir/shared/glob.rb | 94 |
3 files changed, 130 insertions, 136 deletions
diff --git a/spec/ruby/core/dir/children_spec.rb b/spec/ruby/core/dir/children_spec.rb index 8f6e62b463..e0325a24b8 100644 --- a/spec/ruby/core/dir/children_spec.rb +++ b/spec/ruby/core/dir/children_spec.rb @@ -3,71 +3,69 @@ require_relative '../../spec_helper' require_relative 'fixtures/common' -ruby_version_is "2.5" do - describe "Dir.children" do - before :all do - DirSpecs.create_mock_dirs - end +describe "Dir.children" do + before :all do + DirSpecs.create_mock_dirs + end - before :each do - @internal = Encoding.default_internal - end + before :each do + @internal = Encoding.default_internal + end - after :all do - DirSpecs.delete_mock_dirs - end + after :all do + DirSpecs.delete_mock_dirs + end - after :each do - Encoding.default_internal = @internal - end + after :each do + Encoding.default_internal = @internal + end - it "returns an Array of filenames in an existing directory including dotfiles" do - a = Dir.children(DirSpecs.mock_dir).sort + it "returns an Array of filenames in an existing directory including dotfiles" do + a = Dir.children(DirSpecs.mock_dir).sort - a.should == DirSpecs.expected_paths - %w[. ..] + a.should == DirSpecs.expected_paths - %w[. ..] - a = Dir.children("#{DirSpecs.mock_dir}/deeply/nested").sort - a.should == %w|.dotfile.ext directory| - end + a = Dir.children("#{DirSpecs.mock_dir}/deeply/nested").sort + a.should == %w|.dotfile.ext directory| + end - it "calls #to_path on non-String arguments" do - p = mock('path') - p.should_receive(:to_path).and_return(DirSpecs.mock_dir) - Dir.children(p) - end + it "calls #to_path on non-String arguments" do + p = mock('path') + p.should_receive(:to_path).and_return(DirSpecs.mock_dir) + Dir.children(p) + end - it "accepts an options Hash" do - a = Dir.children("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8").sort - a.should == %w|.dotfile.ext directory| - end + it "accepts an options Hash" do + a = Dir.children("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8").sort + a.should == %w|.dotfile.ext directory| + end - it "returns children encoded with the filesystem encoding by default" do - # This spec depends on the locale not being US-ASCII because if it is, the - # children that are not ascii_only? will be BINARY encoded. - children = Dir.children(File.join(DirSpecs.mock_dir, 'special')).sort - encoding = Encoding.find("filesystem") - encoding = Encoding::BINARY if encoding == Encoding::US_ASCII - platform_is_not :windows do - children.should include("こんにちは.txt".force_encoding(encoding)) - end - children.first.encoding.should equal(Encoding.find("filesystem")) + it "returns children encoded with the filesystem encoding by default" do + # This spec depends on the locale not being US-ASCII because if it is, the + # children that are not ascii_only? will be BINARY encoded. + children = Dir.children(File.join(DirSpecs.mock_dir, 'special')).sort + encoding = Encoding.find("filesystem") + encoding = Encoding::BINARY if encoding == Encoding::US_ASCII + platform_is_not :windows do + children.should include("こんにちは.txt".force_encoding(encoding)) end + children.first.encoding.should equal(Encoding.find("filesystem")) + end - it "returns children encoded with the specified encoding" do - dir = File.join(DirSpecs.mock_dir, 'special') - children = Dir.children(dir, encoding: "euc-jp").sort - children.first.encoding.should equal(Encoding::EUC_JP) - end + it "returns children encoded with the specified encoding" do + dir = File.join(DirSpecs.mock_dir, 'special') + children = Dir.children(dir, encoding: "euc-jp").sort + children.first.encoding.should equal(Encoding::EUC_JP) + end - it "returns children transcoded to the default internal encoding" do - Encoding.default_internal = Encoding::EUC_KR - children = Dir.children(File.join(DirSpecs.mock_dir, 'special')).sort - children.first.encoding.should equal(Encoding::EUC_KR) - end + it "returns children transcoded to the default internal encoding" do + Encoding.default_internal = Encoding::EUC_KR + children = Dir.children(File.join(DirSpecs.mock_dir, 'special')).sort + children.first.encoding.should equal(Encoding::EUC_KR) + end - it "raises a SystemCallError if called with a nonexistent directory" do - -> { Dir.children DirSpecs.nonexistent }.should raise_error(SystemCallError) - end + it "raises a SystemCallError if called with a nonexistent directory" do + -> { Dir.children DirSpecs.nonexistent }.should raise_error(SystemCallError) end end diff --git a/spec/ruby/core/dir/each_child_spec.rb b/spec/ruby/core/dir/each_child_spec.rb index dcc9a456c7..93b4a1aec1 100644 --- a/spec/ruby/core/dir/each_child_spec.rb +++ b/spec/ruby/core/dir/each_child_spec.rb @@ -1,51 +1,49 @@ require_relative '../../spec_helper' require_relative 'fixtures/common' -ruby_version_is "2.5" do - describe "Dir.each_child" do - before :all do - DirSpecs.create_mock_dirs - end +describe "Dir.each_child" do + before :all do + DirSpecs.create_mock_dirs + end - after :all do - DirSpecs.delete_mock_dirs - end + after :all do + DirSpecs.delete_mock_dirs + end - it "yields all names in an existing directory to the provided block" do - a, b = [], [] + it "yields all names in an existing directory to the provided block" do + a, b = [], [] - Dir.each_child(DirSpecs.mock_dir) {|f| a << f} - Dir.each_child("#{DirSpecs.mock_dir}/deeply/nested") {|f| b << f} + Dir.each_child(DirSpecs.mock_dir) {|f| a << f} + Dir.each_child("#{DirSpecs.mock_dir}/deeply/nested") {|f| b << f} - a.sort.should == DirSpecs.expected_paths - %w[. ..] - b.sort.should == %w|.dotfile.ext directory| - end + a.sort.should == DirSpecs.expected_paths - %w[. ..] + b.sort.should == %w|.dotfile.ext directory| + end - it "returns nil when successful" do - Dir.each_child(DirSpecs.mock_dir) {|f| f}.should == nil - end + it "returns nil when successful" do + Dir.each_child(DirSpecs.mock_dir) {|f| f}.should == nil + end - it "calls #to_path on non-String arguments" do - p = mock('path') - p.should_receive(:to_path).and_return(DirSpecs.mock_dir) - Dir.each_child(p).to_a - end + it "calls #to_path on non-String arguments" do + p = mock('path') + p.should_receive(:to_path).and_return(DirSpecs.mock_dir) + Dir.each_child(p).to_a + end - it "raises a SystemCallError if passed a nonexistent directory" do - -> { Dir.each_child(DirSpecs.nonexistent) {} }.should raise_error(SystemCallError) - end + it "raises a SystemCallError if passed a nonexistent directory" do + -> { Dir.each_child(DirSpecs.nonexistent) {} }.should raise_error(SystemCallError) + end - describe "when no block is given" do - it "returns an Enumerator" do - Dir.each_child(DirSpecs.mock_dir).should be_an_instance_of(Enumerator) - Dir.each_child(DirSpecs.mock_dir).to_a.sort.should == DirSpecs.expected_paths - %w[. ..] - end + describe "when no block is given" do + it "returns an Enumerator" do + Dir.each_child(DirSpecs.mock_dir).should be_an_instance_of(Enumerator) + Dir.each_child(DirSpecs.mock_dir).to_a.sort.should == DirSpecs.expected_paths - %w[. ..] + end - describe "returned Enumerator" do - describe "size" do - it "should return nil" do - Dir.each_child(DirSpecs.mock_dir).size.should == nil - end + describe "returned Enumerator" do + describe "size" do + it "should return nil" do + Dir.each_child(DirSpecs.mock_dir).size.should == nil end end end 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 |