1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

File.dirname optional level

* file.c (rb_file_dirname_n): chomp N level of base names.
  [Feature #12194]
This commit is contained in:
Nobuyoshi Nakada 2016-03-18 16:40:45 +09:00
parent ba9de878a6
commit 82b6f89283
Notes: git 2021-03-15 15:09:28 +09:00
3 changed files with 78 additions and 6 deletions

View file

@ -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