Skip to content

Commit

Permalink
File.dirname optional level
Browse files Browse the repository at this point in the history
* file.c (rb_file_dirname_n): chomp N level of base names.
  [Feature #12194]
  • Loading branch information
nobu authored and eregon committed Mar 27, 2021
1 parent 1661581 commit 1db2492
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/file/dirname_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
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
Expand Down

0 comments on commit 1db2492

Please sign in to comment.