aboutsummaryrefslogtreecommitdiffstats
path: root/spec/rubyspec/library/pathname
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubyspec/library/pathname')
-rw-r--r--spec/rubyspec/library/pathname/absolute_spec.rb23
-rw-r--r--spec/rubyspec/library/pathname/equal_value_spec.rb15
-rw-r--r--spec/rubyspec/library/pathname/hash_spec.rb15
-rw-r--r--spec/rubyspec/library/pathname/join_spec.rb40
-rw-r--r--spec/rubyspec/library/pathname/new_spec.rb28
-rw-r--r--spec/rubyspec/library/pathname/parent_spec.rb19
-rw-r--r--spec/rubyspec/library/pathname/realdirpath_spec.rb10
-rw-r--r--spec/rubyspec/library/pathname/realpath_spec.rb10
-rw-r--r--spec/rubyspec/library/pathname/relative_path_from_spec.rb51
-rw-r--r--spec/rubyspec/library/pathname/relative_spec.rb23
-rw-r--r--spec/rubyspec/library/pathname/root_spec.rb27
-rw-r--r--spec/rubyspec/library/pathname/sub_spec.rb16
12 files changed, 277 insertions, 0 deletions
diff --git a/spec/rubyspec/library/pathname/absolute_spec.rb b/spec/rubyspec/library/pathname/absolute_spec.rb
new file mode 100644
index 0000000000..af0639493a
--- /dev/null
+++ b/spec/rubyspec/library/pathname/absolute_spec.rb
@@ -0,0 +1,23 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'pathname'
+
+describe "Pathname#absolute?" do
+
+ it "returns true for the root directory" do
+ Pathname.new('/').absolute?.should == true
+ end
+
+ it "returns true for a dir starting with a slash" do
+ Pathname.new('/usr/local/bin').absolute?.should == true
+ end
+
+ it "returns false for a dir not starting with a slash" do
+ Pathname.new('fish').absolute?.should == false
+ end
+
+ it "returns false for a dir not starting with a slash" do
+ Pathname.new('fish/dog/cow').absolute?.should == false
+ end
+
+end
+
diff --git a/spec/rubyspec/library/pathname/equal_value_spec.rb b/spec/rubyspec/library/pathname/equal_value_spec.rb
new file mode 100644
index 0000000000..afcdb08de8
--- /dev/null
+++ b/spec/rubyspec/library/pathname/equal_value_spec.rb
@@ -0,0 +1,15 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'pathname'
+
+describe "Pathname#==" do
+
+ it "returns true when identical paths are used" do
+ (Pathname.new('') == Pathname.new('')).should == true
+ end
+
+ it "returns true when identical paths are used" do
+ (Pathname.new('') == Pathname.new('/usr/local/bin')).should == false
+ end
+
+end
+
diff --git a/spec/rubyspec/library/pathname/hash_spec.rb b/spec/rubyspec/library/pathname/hash_spec.rb
new file mode 100644
index 0000000000..f3201e2f4f
--- /dev/null
+++ b/spec/rubyspec/library/pathname/hash_spec.rb
@@ -0,0 +1,15 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'pathname'
+
+describe "Pathname#hash" do
+
+ it "is equal to the hash of the pathname" do
+ Pathname.new('/usr/local/bin/').hash.should == '/usr/local/bin/'.hash
+ end
+
+ it "is not equal the hash of a different pathname" do
+ Pathname.new('/usr/local/bin/').hash.should_not == '/usr/bin/'.hash
+ end
+
+end
+
diff --git a/spec/rubyspec/library/pathname/join_spec.rb b/spec/rubyspec/library/pathname/join_spec.rb
new file mode 100644
index 0000000000..8c77bb1f59
--- /dev/null
+++ b/spec/rubyspec/library/pathname/join_spec.rb
@@ -0,0 +1,40 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'pathname'
+
+describe "Pathname#join" do
+ it "without separators" do
+ Pathname.new('/usr').join(Pathname.new('foo')).should == Pathname.new('/usr/foo')
+ end
+
+ it "with separators" do
+ Pathname.new('/usr').join(Pathname.new('/foo')).should == Pathname.new('/foo')
+ end
+
+ it "with a string" do
+ Pathname.new('/usr').join('foo').should == Pathname.new('/usr/foo')
+ end
+
+ it "with root" do
+ Pathname.new('/usr').join(Pathname.new('/')).should == Pathname.new('/')
+ end
+
+ it "with a relative path" do
+ Pathname.new('/usr').join(Pathname.new('../foo')).should == Pathname.new('/foo')
+ end
+
+ it "a relative path with current" do
+ Pathname.new('.').join(Pathname.new('foo')).should == Pathname.new('foo')
+ end
+
+ it "an absolute path with current" do
+ Pathname.new('.').join(Pathname.new('/foo')).should == Pathname.new('/foo')
+ end
+
+ it "a prefixed relative path with current" do
+ Pathname.new('.').join(Pathname.new('./foo')).should == Pathname.new('foo')
+ end
+
+ it "multiple paths" do
+ Pathname.new('.').join(Pathname.new('./foo'), 'bar').should == Pathname.new('foo/bar')
+ end
+end
diff --git a/spec/rubyspec/library/pathname/new_spec.rb b/spec/rubyspec/library/pathname/new_spec.rb
new file mode 100644
index 0000000000..a888e98736
--- /dev/null
+++ b/spec/rubyspec/library/pathname/new_spec.rb
@@ -0,0 +1,28 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'pathname'
+
+describe "Pathname.new" do
+ it "returns a new Pathname Object with 1 argument" do
+ Pathname.new('').should be_kind_of(Pathname)
+ end
+
+ it "raises an ArgumentError when called with \0" do
+ lambda { Pathname.new("\0")}.should raise_error(ArgumentError)
+ end
+
+ it "is tainted if path is tainted" do
+ path = '/usr/local/bin'.taint
+ Pathname.new(path).tainted?.should == true
+ end
+
+ it "raises a TypeError if not passed a String type" do
+ lambda { Pathname.new(nil) }.should raise_error(TypeError)
+ lambda { Pathname.new(0) }.should raise_error(TypeError)
+ lambda { Pathname.new(true) }.should raise_error(TypeError)
+ lambda { Pathname.new(false) }.should raise_error(TypeError)
+ end
+
+ it "initializes with an object with to_path" do
+ Pathname.new(mock_to_path('foo')).should == Pathname.new('foo')
+ end
+end
diff --git a/spec/rubyspec/library/pathname/parent_spec.rb b/spec/rubyspec/library/pathname/parent_spec.rb
new file mode 100644
index 0000000000..53d3f1e50e
--- /dev/null
+++ b/spec/rubyspec/library/pathname/parent_spec.rb
@@ -0,0 +1,19 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'pathname'
+
+describe "Pathname#parent" do
+
+ it "has parent of root as root" do
+ Pathname.new('/').parent.to_s.should == '/'
+ end
+
+ it "has parent of /usr/ as root" do
+ Pathname.new('/usr/').parent.to_s.should == '/'
+ end
+
+ it "has parent of /usr/local as root" do
+ Pathname.new('/usr/local').parent.to_s.should == '/usr'
+ end
+
+end
+
diff --git a/spec/rubyspec/library/pathname/realdirpath_spec.rb b/spec/rubyspec/library/pathname/realdirpath_spec.rb
new file mode 100644
index 0000000000..f76e37602c
--- /dev/null
+++ b/spec/rubyspec/library/pathname/realdirpath_spec.rb
@@ -0,0 +1,10 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'pathname'
+
+describe "Pathname#realdirpath" do
+
+ it "returns a Pathname" do
+ Pathname.pwd.realdirpath.should be_an_instance_of(Pathname)
+ end
+
+end
diff --git a/spec/rubyspec/library/pathname/realpath_spec.rb b/spec/rubyspec/library/pathname/realpath_spec.rb
new file mode 100644
index 0000000000..e1c9eb34ea
--- /dev/null
+++ b/spec/rubyspec/library/pathname/realpath_spec.rb
@@ -0,0 +1,10 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'pathname'
+
+describe "Pathname#realpath" do
+
+ it "returns a Pathname" do
+ Pathname.pwd.realpath.should be_an_instance_of(Pathname)
+ end
+
+end
diff --git a/spec/rubyspec/library/pathname/relative_path_from_spec.rb b/spec/rubyspec/library/pathname/relative_path_from_spec.rb
new file mode 100644
index 0000000000..b3bc85e307
--- /dev/null
+++ b/spec/rubyspec/library/pathname/relative_path_from_spec.rb
@@ -0,0 +1,51 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'pathname'
+
+describe "Pathname#relative_path_from" do
+ def relative_path_str(dest, base)
+ Pathname.new(dest).relative_path_from(Pathname.new(base)).to_s
+ end
+
+ it "raises an error when the two paths do not share a common prefix" do
+ lambda { relative_path_str('/usr', 'foo') }.should raise_error(ArgumentError)
+ end
+
+ it "raises an error when the base directory has .." do
+ lambda { relative_path_str('a', '..') }.should raise_error(ArgumentError)
+ end
+
+ it "retuns a path relative from root" do
+ relative_path_str('/usr', '/').should == 'usr'
+ end
+
+ it 'returns 1 level up when both paths are relative' do
+ relative_path_str('a', 'b').should == '../a'
+ relative_path_str('a', 'b/').should == '../a'
+ end
+
+ it 'returns a relative path when both are absolute' do
+ relative_path_str('/a', '/b').should == '../a'
+ end
+
+ it "returns a path relative to the current directory" do
+ relative_path_str('/usr/bin/ls', '/usr').should == 'bin/ls'
+ end
+
+ it 'returns a . when base and dest are the same' do
+ relative_path_str('/usr', '/usr').should == '.'
+ end
+
+ it 'returns the same directory with a non clean base that matches the current dir' do
+ relative_path_str('/usr', '/stuff/..').should == 'usr'
+ end
+
+ it 'returns a relative path with a non clean base that matches a different dir' do
+ relative_path_str('/usr', '/stuff/../foo').should == '../usr'
+ end
+
+ it 'returns current and pattern when only those patterns are used' do
+ relative_path_str('.', '.').should == '.'
+ relative_path_str('..', '..').should == '.'
+ relative_path_str('..', '.').should == '..'
+ end
+end
diff --git a/spec/rubyspec/library/pathname/relative_spec.rb b/spec/rubyspec/library/pathname/relative_spec.rb
new file mode 100644
index 0000000000..a44d8c5a66
--- /dev/null
+++ b/spec/rubyspec/library/pathname/relative_spec.rb
@@ -0,0 +1,23 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'pathname'
+
+describe "Pathname#relative?" do
+
+ it "returns false for the root directory" do
+ Pathname.new('/').relative?.should == false
+ end
+
+ it "returns false for a dir starting with a slash" do
+ Pathname.new('/usr/local/bin').relative?.should == false
+ end
+
+ it "returns true for a dir not starting with a slash" do
+ Pathname.new('fish').relative?.should == true
+ end
+
+ it "returns true for a dir not starting with a slash" do
+ Pathname.new('fish/dog/cow').relative?.should == true
+ end
+
+end
+
diff --git a/spec/rubyspec/library/pathname/root_spec.rb b/spec/rubyspec/library/pathname/root_spec.rb
new file mode 100644
index 0000000000..a5efcf69b4
--- /dev/null
+++ b/spec/rubyspec/library/pathname/root_spec.rb
@@ -0,0 +1,27 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'pathname'
+
+describe "Pathname#root?" do
+
+ it "returns true for root directories" do
+ Pathname.new('/').root?.should == true
+ end
+
+ it "returns false for empty string" do
+ Pathname.new('').root?.should == false
+ end
+
+ it "returns false for a top level directory" do
+ Pathname.new('/usr').root?.should == false
+ end
+
+ it "returns false for a top level with .. appended directory" do
+ Pathname.new('/usr/..').root?.should == false
+ end
+
+ it "returns false for a directory below top level" do
+ Pathname.new('/usr/local/bin/').root?.should == false
+ end
+
+end
+
diff --git a/spec/rubyspec/library/pathname/sub_spec.rb b/spec/rubyspec/library/pathname/sub_spec.rb
new file mode 100644
index 0000000000..36b6ebb247
--- /dev/null
+++ b/spec/rubyspec/library/pathname/sub_spec.rb
@@ -0,0 +1,16 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'pathname'
+
+describe "Pathname#sub" do
+
+ it "replaces the pattern with rest" do
+ Pathname.new('/usr/local/bin/').sub(/local/, 'fish').to_s.should == '/usr/fish/bin/'
+ end
+
+ it "returns a new object" do
+ p = Pathname.new('/usr/local/bin/')
+ p.sub(/local/, 'fish').should_not == p
+ end
+
+end
+