diff options
Diffstat (limited to 'spec/ruby/library/pathname')
| -rw-r--r-- | spec/ruby/library/pathname/birthtime_spec.rb | 16 | ||||
| -rw-r--r-- | spec/ruby/library/pathname/empty_spec.rb | 8 | ||||
| -rw-r--r-- | spec/ruby/library/pathname/glob_spec.rb | 59 | ||||
| -rw-r--r-- | spec/ruby/library/pathname/inspect_spec.rb | 2 | ||||
| -rw-r--r-- | spec/ruby/library/pathname/new_spec.rb | 19 | ||||
| -rw-r--r-- | spec/ruby/library/pathname/pathname_spec.rb | 23 | ||||
| -rw-r--r-- | spec/ruby/library/pathname/realdirpath_spec.rb | 2 | ||||
| -rw-r--r-- | spec/ruby/library/pathname/realpath_spec.rb | 2 | ||||
| -rw-r--r-- | spec/ruby/library/pathname/relative_path_from_spec.rb | 8 |
9 files changed, 88 insertions, 51 deletions
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/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 index f6dfd6cd58..e20e6f8f85 100644 --- a/spec/ruby/library/pathname/glob_spec.rb +++ b/spec/ruby/library/pathname/glob_spec.rb @@ -21,6 +21,10 @@ describe 'Pathname.glob' 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 @@ -37,21 +41,52 @@ describe 'Pathname.glob' do it "raises an ArgumentError when supplied a keyword argument other than :base" do -> { Pathname.glob('*i*.rb', foo: @dir + 'lib') - }.should raise_error(ArgumentError, /unknown keyword: :?foo/) + }.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' - ruby_version_is ''...'2.7' do - it 'raises an ArgumentError when supplied a flag and :base keyword argument' do - -> { - Pathname.glob(@dir + 'lib/*i*.rb', File::FNM_DOTMATCH, base: 'lib') - }.should raise_error(ArgumentError, 'wrong number of arguments (given 3, expected 1..2)') - end + touch @file_1 + touch @file_2 + touch @file_3 end - ruby_version_is "2.7" do - 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 + 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 index 304746fbe5..3abba6cbb5 100644 --- a/spec/ruby/library/pathname/inspect_spec.rb +++ b/spec/ruby/library/pathname/inspect_spec.rb @@ -4,7 +4,7 @@ require 'pathname' describe "Pathname#inspect" do it "returns a consistent String" do result = Pathname.new('/tmp').inspect - result.should be_an_instance_of(String) + 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 760fd8638f..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).should.tainted? - 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 index 7d63fe86e3..6fa6fd2bcb 100644 --- a/spec/ruby/library/pathname/pathname_spec.rb +++ b/spec/ruby/library/pathname/pathname_spec.rb @@ -3,28 +3,17 @@ require 'pathname' describe "Kernel#Pathname" do it "is a private instance method" do - Kernel.should have_private_instance_method(:Pathname) + Kernel.private_instance_methods(false).should.include?(:Pathname) end it "is also a public method" do - Kernel.should have_method(:Pathname) + Kernel.should.respond_to?(:Pathname) end - ruby_version_is ''...'2.7' do - it "returns a new pathname when called with a pathname argument" do - path = Pathname('foo') - new_path = Pathname(path) + it "returns same argument when called with a pathname argument" do + path = Pathname('foo') + new_path = Pathname(path) - path.should_not.equal?(new_path) - end - end - - ruby_version_is '2.7' do - it "returns same argument when called with a pathname argument" do - path = Pathname('foo') - new_path = Pathname(path) - - path.should.equal?(new_path) - end + path.should.equal?(new_path) end 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 |
