From b6d163e7ec14b214d12cc854789d05f71834efdd Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Mon, 28 Sep 2026 19:31:38 -0500 Subject: [PATCH] Add Pathname#ascend specs --- library/pathname/ascend_spec.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 library/pathname/ascend_spec.rb diff --git a/library/pathname/ascend_spec.rb b/library/pathname/ascend_spec.rb new file mode 100644 index 000000000..d706e4c58 --- /dev/null +++ b/library/pathname/ascend_spec.rb @@ -0,0 +1,28 @@ +require_relative '../../spec_helper' +require 'pathname' + +describe "Pathname#ascend" do + it "yields paths from an absolute path to the root" do + Pathname.new('/a/b/c').ascend.map(&:to_s).should == ['/a/b/c', '/a/b', '/a', '/'] + end + + it "yields paths from a relative path to its first component" do + Pathname.new('a/b/c').ascend.map(&:to_s).should == ['a/b/c', 'a/b', 'a'] + end + + it "preserves an explicit current directory prefix" do + Pathname.new('./a/b/c').ascend.map(&:to_s).should == ['./a/b/c', './a/b', './a', '.'] + end + + it "preserves a trailing separator on the first path" do + Pathname.new('a/').ascend.map(&:to_s).should == ['a/'] + end + + it "returns nil when given a block" do + Pathname.new('a/b').ascend { |_| }.should == nil + end + + it "returns an Enumerator without a block" do + Pathname.new('a').ascend.should.is_a?(Enumerator) + end +end