summaryrefslogtreecommitdiff
path: root/spec/ruby/library/pathname
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/pathname')
-rw-r--r--spec/ruby/library/pathname/absolute_spec.rb8
-rw-r--r--spec/ruby/library/pathname/birthtime_spec.rb16
-rw-r--r--spec/ruby/library/pathname/divide_spec.rb6
-rw-r--r--spec/ruby/library/pathname/empty_spec.rb8
-rw-r--r--spec/ruby/library/pathname/glob_spec.rb92
-rw-r--r--spec/ruby/library/pathname/inspect_spec.rb10
-rw-r--r--spec/ruby/library/pathname/new_spec.rb19
-rw-r--r--spec/ruby/library/pathname/pathname_spec.rb19
-rw-r--r--spec/ruby/library/pathname/plus_spec.rb6
-rw-r--r--spec/ruby/library/pathname/realdirpath_spec.rb2
-rw-r--r--spec/ruby/library/pathname/realpath_spec.rb2
-rw-r--r--spec/ruby/library/pathname/relative_path_from_spec.rb8
-rw-r--r--spec/ruby/library/pathname/relative_spec.rb8
-rw-r--r--spec/ruby/library/pathname/root_spec.rb10
-rw-r--r--spec/ruby/library/pathname/shared/plus.rb8
15 files changed, 188 insertions, 34 deletions
diff --git a/spec/ruby/library/pathname/absolute_spec.rb b/spec/ruby/library/pathname/absolute_spec.rb
index dce3ae72ee..109abb8ee9 100644
--- a/spec/ruby/library/pathname/absolute_spec.rb
+++ b/spec/ruby/library/pathname/absolute_spec.rb
@@ -4,19 +4,19 @@ require 'pathname'
describe "Pathname#absolute?" do
it "returns true for the root directory" do
- Pathname.new('/').absolute?.should == true
+ Pathname.new('/').should.absolute?
end
it "returns true for a dir starting with a slash" do
- Pathname.new('/usr/local/bin').absolute?.should == true
+ Pathname.new('/usr/local/bin').should.absolute?
end
it "returns false for a dir not starting with a slash" do
- Pathname.new('fish').absolute?.should == false
+ Pathname.new('fish').should_not.absolute?
end
it "returns false for a dir not starting with a slash" do
- Pathname.new('fish/dog/cow').absolute?.should == false
+ Pathname.new('fish/dog/cow').should_not.absolute?
end
end
diff --git a/spec/ruby/library/pathname/birthtime_spec.rb b/spec/ruby/library/pathname/birthtime_spec.rb
new file mode 100644
index 0000000000..387f0aa54d
--- /dev/null
+++ b/spec/ruby/library/pathname/birthtime_spec.rb
@@ -0,0 +1,16 @@
+require_relative '../../spec_helper'
+require 'pathname'
+
+describe "Pathname#birthtime" do
+ platform_is :windows, :darwin, :freebsd, :netbsd do
+ it "returns the birth time for self" do
+ Pathname.new(__FILE__).birthtime.should.is_a?(Time)
+ end
+ end
+
+ platform_is :openbsd do
+ it "raises an NotImplementedError" do
+ -> { Pathname.new(__FILE__).birthtime }.should.raise(NotImplementedError)
+ end
+ end
+end
diff --git a/spec/ruby/library/pathname/divide_spec.rb b/spec/ruby/library/pathname/divide_spec.rb
new file mode 100644
index 0000000000..8af79d0c8f
--- /dev/null
+++ b/spec/ruby/library/pathname/divide_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative 'shared/plus'
+
+describe "Pathname#/" do
+ it_behaves_like :pathname_plus, :/
+end
diff --git a/spec/ruby/library/pathname/empty_spec.rb b/spec/ruby/library/pathname/empty_spec.rb
index 4deade5b64..9f0305a0f0 100644
--- a/spec/ruby/library/pathname/empty_spec.rb
+++ b/spec/ruby/library/pathname/empty_spec.rb
@@ -15,18 +15,18 @@ describe 'Pathname#empty?' do
end
it 'returns true when file is not empty' do
- Pathname.new(__FILE__).empty?.should be_false
+ Pathname.new(__FILE__).empty?.should == false
end
it 'returns false when the directory is not empty' do
- Pathname.new(__dir__).empty?.should be_false
+ Pathname.new(__dir__).empty?.should == false
end
it 'return true when file is empty' do
- Pathname.new(@file).empty?.should be_true
+ Pathname.new(@file).empty?.should == true
end
it 'returns true when directory is empty' do
- Pathname.new(@dir).empty?.should be_true
+ Pathname.new(@dir).empty?.should == true
end
end
diff --git a/spec/ruby/library/pathname/glob_spec.rb b/spec/ruby/library/pathname/glob_spec.rb
new file mode 100644
index 0000000000..e20e6f8f85
--- /dev/null
+++ b/spec/ruby/library/pathname/glob_spec.rb
@@ -0,0 +1,92 @@
+require_relative '../../spec_helper'
+require 'pathname'
+
+describe 'Pathname.glob' do
+ before :all do
+ @dir = tmp('pathname_glob') + '/'
+ @file_1 = @dir + 'lib/ipaddr.rb'
+ @file_2 = @dir + 'lib/irb.rb'
+ @file_3 = @dir + 'lib/.hidden.rb'
+
+ touch @file_1
+ touch @file_2
+ touch @file_3
+ end
+
+ after :all do
+ rm_r @dir[0...-1]
+ end
+
+ it 'returns [] for no match' do
+ Pathname.glob(@dir + 'lib/*.js').should == []
+ end
+
+ it 'returns [] when the pathname does not exist' do
+ Pathname.glob('i_dont_exist/lib/*.js').should == []
+ end
+
+ it 'returns matching file paths' do
+ Pathname.glob(@dir + 'lib/*i*.rb').sort.should == [Pathname.new(@file_1), Pathname.new(@file_2)].sort
+ end
+
+ it 'returns matching file paths when a flag is provided' do
+ expected = [Pathname.new(@file_1), Pathname.new(@file_2), Pathname.new(@file_3)].sort
+ Pathname.glob(@dir + 'lib/*i*.rb', File::FNM_DOTMATCH).sort.should == expected
+ end
+
+ it 'returns matching file paths when supplied :base keyword argument' do
+ Pathname.glob('*i*.rb', base: @dir + 'lib').sort.should == [Pathname.new('ipaddr.rb'), Pathname.new('irb.rb')].sort
+ end
+
+ it "raises an ArgumentError when supplied a keyword argument other than :base" do
+ -> {
+ Pathname.glob('*i*.rb', foo: @dir + 'lib')
+ }.should.raise(ArgumentError, "unknown keyword: :foo")
+ end
+
+ it "does not raise an ArgumentError when supplied a flag and :base keyword argument" do
+ expected = [Pathname.new('ipaddr.rb'), Pathname.new('irb.rb'), Pathname.new('.hidden.rb')].sort
+ Pathname.glob('*i*.rb', File::FNM_DOTMATCH, base: @dir + 'lib').sort.should == expected
+ end
+end
+
+
+describe 'Pathname#glob' do
+ before :all do
+ @dir = tmp('pathname_glob') + '/'
+ @file_1 = @dir + 'lib/ipaddr.rb'
+ @file_2 = @dir + 'lib/irb.rb'
+ @file_3 = @dir + 'lib/.hidden.rb'
+
+ touch @file_1
+ touch @file_2
+ touch @file_3
+ end
+
+ after :all do
+ rm_r @dir[0...-1]
+ end
+
+ it 'returns [] for no match' do
+ Pathname.new(@dir).glob('lib/*.js').should == []
+ end
+
+ it 'returns [] when the pathname does not exist' do
+ Pathname.new('./i_dont_exist').glob('lib/*.js').should == []
+ end
+
+ it 'returns matching file paths' do
+ Pathname.new(@dir).glob('lib/*i*.rb').sort.should == [Pathname.new(@file_1), Pathname.new(@file_2)].sort
+ end
+
+ it 'yields matching file paths to block' do
+ ary = []
+ Pathname.new(@dir).glob('lib/*i*.rb') { |p| ary << p }.should == nil
+ ary.sort.should == [Pathname.new(@file_1), Pathname.new(@file_2)].sort
+ end
+
+ it 'returns matching file paths when a flag is provided' do
+ expected = [Pathname.new(@file_1), Pathname.new(@file_2), Pathname.new(@file_3)].sort
+ Pathname.new(@dir).glob('lib/*i*.rb', File::FNM_DOTMATCH).sort.should == expected
+ end
+end
diff --git a/spec/ruby/library/pathname/inspect_spec.rb b/spec/ruby/library/pathname/inspect_spec.rb
new file mode 100644
index 0000000000..3abba6cbb5
--- /dev/null
+++ b/spec/ruby/library/pathname/inspect_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+require 'pathname'
+
+describe "Pathname#inspect" do
+ it "returns a consistent String" do
+ result = Pathname.new('/tmp').inspect
+ result.should.instance_of?(String)
+ result.should == "#<Pathname:/tmp>"
+ end
+end
diff --git a/spec/ruby/library/pathname/new_spec.rb b/spec/ruby/library/pathname/new_spec.rb
index dcb770149f..3ef9d9b76d 100644
--- a/spec/ruby/library/pathname/new_spec.rb
+++ b/spec/ruby/library/pathname/new_spec.rb
@@ -3,25 +3,18 @@ require 'pathname'
describe "Pathname.new" do
it "returns a new Pathname Object with 1 argument" do
- Pathname.new('').should be_kind_of(Pathname)
+ Pathname.new('').should.is_a?(Pathname)
end
it "raises an ArgumentError when called with \0" do
- -> { Pathname.new("\0")}.should raise_error(ArgumentError)
- end
-
- ruby_version_is ''...'2.7' do
- it "is tainted if path is tainted" do
- path = '/usr/local/bin'.taint
- Pathname.new(path).tainted?.should == true
- end
+ -> { Pathname.new("\0")}.should.raise(ArgumentError)
end
it "raises a TypeError if not passed a String type" do
- -> { Pathname.new(nil) }.should raise_error(TypeError)
- -> { Pathname.new(0) }.should raise_error(TypeError)
- -> { Pathname.new(true) }.should raise_error(TypeError)
- -> { Pathname.new(false) }.should raise_error(TypeError)
+ -> { Pathname.new(nil) }.should.raise(TypeError)
+ -> { Pathname.new(0) }.should.raise(TypeError)
+ -> { Pathname.new(true) }.should.raise(TypeError)
+ -> { Pathname.new(false) }.should.raise(TypeError)
end
it "initializes with an object with to_path" do
diff --git a/spec/ruby/library/pathname/pathname_spec.rb b/spec/ruby/library/pathname/pathname_spec.rb
new file mode 100644
index 0000000000..6fa6fd2bcb
--- /dev/null
+++ b/spec/ruby/library/pathname/pathname_spec.rb
@@ -0,0 +1,19 @@
+require_relative '../../spec_helper'
+require 'pathname'
+
+describe "Kernel#Pathname" do
+ it "is a private instance method" do
+ Kernel.private_instance_methods(false).should.include?(:Pathname)
+ end
+
+ it "is also a public method" do
+ Kernel.should.respond_to?(:Pathname)
+ end
+
+ it "returns same argument when called with a pathname argument" do
+ path = Pathname('foo')
+ new_path = Pathname(path)
+
+ path.should.equal?(new_path)
+ end
+end
diff --git a/spec/ruby/library/pathname/plus_spec.rb b/spec/ruby/library/pathname/plus_spec.rb
new file mode 100644
index 0000000000..57e472c266
--- /dev/null
+++ b/spec/ruby/library/pathname/plus_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative 'shared/plus'
+
+describe "Pathname#+" do
+ it_behaves_like :pathname_plus, :+
+end
diff --git a/spec/ruby/library/pathname/realdirpath_spec.rb b/spec/ruby/library/pathname/realdirpath_spec.rb
index a9e44e354e..e50741a737 100644
--- a/spec/ruby/library/pathname/realdirpath_spec.rb
+++ b/spec/ruby/library/pathname/realdirpath_spec.rb
@@ -4,7 +4,7 @@ require 'pathname'
describe "Pathname#realdirpath" do
it "returns a Pathname" do
- Pathname.pwd.realdirpath.should be_an_instance_of(Pathname)
+ Pathname.pwd.realdirpath.should.instance_of?(Pathname)
end
end
diff --git a/spec/ruby/library/pathname/realpath_spec.rb b/spec/ruby/library/pathname/realpath_spec.rb
index f2c654308e..d8b87f57d0 100644
--- a/spec/ruby/library/pathname/realpath_spec.rb
+++ b/spec/ruby/library/pathname/realpath_spec.rb
@@ -4,7 +4,7 @@ require 'pathname'
describe "Pathname#realpath" do
it "returns a Pathname" do
- Pathname.pwd.realpath.should be_an_instance_of(Pathname)
+ Pathname.pwd.realpath.should.instance_of?(Pathname)
end
end
diff --git a/spec/ruby/library/pathname/relative_path_from_spec.rb b/spec/ruby/library/pathname/relative_path_from_spec.rb
index abe9c80a45..7cbd22c3d6 100644
--- a/spec/ruby/library/pathname/relative_path_from_spec.rb
+++ b/spec/ruby/library/pathname/relative_path_from_spec.rb
@@ -7,11 +7,11 @@ describe "Pathname#relative_path_from" do
end
it "raises an error when the two paths do not share a common prefix" do
- -> { relative_path_str('/usr', 'foo') }.should raise_error(ArgumentError)
+ -> { relative_path_str('/usr', 'foo') }.should.raise(ArgumentError)
end
it "raises an error when the base directory has .." do
- -> { relative_path_str('a', '..') }.should raise_error(ArgumentError)
+ -> { relative_path_str('a', '..') }.should.raise(ArgumentError)
end
it "returns a path relative from root" do
@@ -48,4 +48,8 @@ describe "Pathname#relative_path_from" do
relative_path_str('..', '..').should == '.'
relative_path_str('..', '.').should == '..'
end
+
+ it 'converts string argument to Pathname' do
+ Pathname.new('/usr/bin/ls').relative_path_from('/usr').to_s.should == 'bin/ls'
+ end
end
diff --git a/spec/ruby/library/pathname/relative_spec.rb b/spec/ruby/library/pathname/relative_spec.rb
index 1a08891e6c..0fab9a7b9f 100644
--- a/spec/ruby/library/pathname/relative_spec.rb
+++ b/spec/ruby/library/pathname/relative_spec.rb
@@ -4,19 +4,19 @@ require 'pathname'
describe "Pathname#relative?" do
it "returns false for the root directory" do
- Pathname.new('/').relative?.should == false
+ Pathname.new('/').should_not.relative?
end
it "returns false for a dir starting with a slash" do
- Pathname.new('/usr/local/bin').relative?.should == false
+ Pathname.new('/usr/local/bin').should_not.relative?
end
it "returns true for a dir not starting with a slash" do
- Pathname.new('fish').relative?.should == true
+ Pathname.new('fish').should.relative?
end
it "returns true for a dir not starting with a slash" do
- Pathname.new('fish/dog/cow').relative?.should == true
+ Pathname.new('fish/dog/cow').should.relative?
end
end
diff --git a/spec/ruby/library/pathname/root_spec.rb b/spec/ruby/library/pathname/root_spec.rb
index 5fec0ee956..cd2be24516 100644
--- a/spec/ruby/library/pathname/root_spec.rb
+++ b/spec/ruby/library/pathname/root_spec.rb
@@ -4,23 +4,23 @@ require 'pathname'
describe "Pathname#root?" do
it "returns true for root directories" do
- Pathname.new('/').root?.should == true
+ Pathname.new('/').should.root?
end
it "returns false for empty string" do
- Pathname.new('').root?.should == false
+ Pathname.new('').should_not.root?
end
it "returns false for a top level directory" do
- Pathname.new('/usr').root?.should == false
+ Pathname.new('/usr').should_not.root?
end
it "returns false for a top level with .. appended directory" do
- Pathname.new('/usr/..').root?.should == false
+ Pathname.new('/usr/..').should_not.root?
end
it "returns false for a directory below top level" do
- Pathname.new('/usr/local/bin/').root?.should == false
+ Pathname.new('/usr/local/bin/').should_not.root?
end
end
diff --git a/spec/ruby/library/pathname/shared/plus.rb b/spec/ruby/library/pathname/shared/plus.rb
new file mode 100644
index 0000000000..b3b896ea43
--- /dev/null
+++ b/spec/ruby/library/pathname/shared/plus.rb
@@ -0,0 +1,8 @@
+require 'pathname'
+
+describe :pathname_plus, shared: true do
+ it "appends a pathname to self" do
+ p = Pathname.new("/usr")
+ p.send(@method, "bin/ruby").should == Pathname.new("/usr/bin/ruby")
+ end
+end