diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2016-03-18 16:40:45 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-03-15 15:09:05 +0900 |
commit | 82b6f89283042b670975f3f7986432647101984e (patch) | |
tree | e1c6e2ff21cd6e8f16fcd60f8356d0c02e4dfade /spec/ruby/core | |
parent | ba9de878a6d303503d8ddbef83598fc1f5c1b80b (diff) | |
download | ruby-82b6f89283042b670975f3f7986432647101984e.tar.gz |
File.dirname optional level
* file.c (rb_file_dirname_n): chomp N level of base names.
[Feature #12194]
Diffstat (limited to 'spec/ruby/core')
-rw-r--r-- | spec/ruby/core/file/dirname_spec.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/spec/ruby/core/file/dirname_spec.rb b/spec/ruby/core/file/dirname_spec.rb index 2ef04a7b64..cf0f909f59 100644 --- a/spec/ruby/core/file/dirname_spec.rb +++ b/spec/ruby/core/file/dirname_spec.rb @@ -11,6 +11,22 @@ describe "File.dirname" do File.dirname('/foo/foo').should == '/foo' end + ruby_version_is '3.1' do + it "returns all the components of filename except the last parts by the level" do + File.dirname('/home/jason', 2).should == '/' + File.dirname('/home/jason/poot.txt', 2).should == '/home' + end + + it "returns the same string if the level is 0" do + File.dirname('poot.txt', 0).should == 'poot.txt' + File.dirname('/', 0).should == '/' + end + + it "raises ArgumentError if the level is negative" do + -> {File.dirname('/home/jason', -1)}.should raise_error(ArgumentError) + end + end + it "returns a String" do File.dirname("foo").should be_kind_of(String) end |