1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
This commit is contained in:
Benoit Daloze 2019-09-29 19:13:37 +02:00
parent d51b4e34fb
commit 070cbe22b7
35 changed files with 127 additions and 133 deletions

View file

@ -95,8 +95,8 @@ describe "Dir.chdir" do
it "raises an Errno::ENOENT if the original directory no longer exists" do it "raises an Errno::ENOENT if the original directory no longer exists" do
dir1 = tmp('/testdir1') dir1 = tmp('/testdir1')
dir2 = tmp('/testdir2') dir2 = tmp('/testdir2')
File.exist?(dir1).should == false File.should_not.exist?(dir1)
File.exist?(dir2).should == false File.should_not.exist?(dir2)
Dir.mkdir dir1 Dir.mkdir dir1
Dir.mkdir dir2 Dir.mkdir dir2
begin begin

View file

@ -14,9 +14,9 @@ describe "Dir.mkdir" do
DirSpecs.clear_dirs DirSpecs.clear_dirs
begin begin
File.exist?('nonexisting').should == false File.should_not.exist?('nonexisting')
Dir.mkdir 'nonexisting' Dir.mkdir 'nonexisting'
File.exist?('nonexisting').should == true File.should.exist?('nonexisting')
platform_is_not :windows do platform_is_not :windows do
Dir.mkdir 'default_perms' Dir.mkdir 'default_perms'
a = File.stat('default_perms').mode a = File.stat('default_perms').mode

View file

@ -16,7 +16,7 @@ describe :dir_chroot_as_root, shared: true do
it "can be used to change the process' root directory" do it "can be used to change the process' root directory" do
-> { Dir.send(@method, File.dirname(__FILE__)) }.should_not raise_error -> { Dir.send(@method, File.dirname(__FILE__)) }.should_not raise_error
File.exist?("/#{File.basename(__FILE__)}").should be_true File.should.exist?("/#{File.basename(__FILE__)}")
end end
it "returns 0 if successful" do it "returns 0 if successful" do
@ -29,8 +29,8 @@ describe :dir_chroot_as_root, shared: true do
it "can be escaped from with ../" do it "can be escaped from with ../" do
Dir.send(@method, @real_root) Dir.send(@method, @real_root)
File.exist?(@ref_dir).should be_true File.should.exist?(@ref_dir)
File.exist?("/#{File.basename(__FILE__)}").should be_false File.should_not.exist?("/#{File.basename(__FILE__)}")
end end
it "calls #to_path on non-String argument" do it "calls #to_path on non-String argument" do

View file

@ -39,7 +39,7 @@ describe :dir_exist, shared: true do
end end
it "returns false if the argument exists but is a file" do it "returns false if the argument exists but is a file" do
File.exist?(__FILE__).should be_true File.should.exist?(__FILE__)
Dir.send(@method, __FILE__).should be_false Dir.send(@method, __FILE__).should be_false
end end

View file

@ -331,14 +331,14 @@ describe :dir_glob, shared: true do
it "returns [] if specified path does not exist" do it "returns [] if specified path does not exist" do
path = File.join(@mock_dir, "fake-name") path = File.join(@mock_dir, "fake-name")
File.exist?(path).should == false File.should_not.exist?(path)
Dir.send(@method, "*", base: path).should == [] Dir.send(@method, "*", base: path).should == []
end end
it "returns [] if specified path is a file" do it "returns [] if specified path is a file" do
path = File.join(@mock_dir, "a/b/x") path = File.join(@mock_dir, "a/b/x")
File.exist?(path).should == true File.should.exist?(path)
Dir.send(@method, "*", base: path).should == [] Dir.send(@method, "*", base: path).should == []
end end

View file

@ -16,7 +16,7 @@ describe "File.link" do
platform_is_not :windows do platform_is_not :windows do
it "link a file with another" do it "link a file with another" do
File.link(@file, @link).should == 0 File.link(@file, @link).should == 0
File.exist?(@link).should == true File.should.exist?(@link)
File.identical?(@file, @link).should == true File.identical?(@file, @link).should == true
end end

View file

@ -17,13 +17,13 @@ describe "File.new" do
it "returns a new File with mode string" do it "returns a new File with mode string" do
@fh = File.new(@file, 'w') @fh = File.new(@file, 'w')
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "returns a new File with mode num" do it "returns a new File with mode num" do
@fh = File.new(@file, @flags) @fh = File.new(@file, @flags)
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "returns a new File with modus num and permissions" do it "returns a new File with modus num and permissions" do
@ -34,7 +34,7 @@ describe "File.new" do
platform_is_not :windows do platform_is_not :windows do
File.stat(@file).mode.to_s(8).should == "100744" File.stat(@file).mode.to_s(8).should == "100744"
end end
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "creates the file and returns writable descriptor when called with 'w' mode and r-o permissions" do it "creates the file and returns writable descriptor when called with 'w' mode and r-o permissions" do
@ -48,7 +48,7 @@ describe "File.new" do
ensure ensure
f.close f.close
end end
File.exist?(@file).should == true File.should.exist?(@file)
File.read(@file).should == "test\n" File.read(@file).should == "test\n"
end end
@ -75,13 +75,13 @@ describe "File.new" do
fh_copy = File.new(@fh.fileno) fh_copy = File.new(@fh.fileno)
fh_copy.autoclose = false fh_copy.autoclose = false
fh_copy.should be_kind_of(File) fh_copy.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "creates a new file when use File::EXCL mode" do it "creates a new file when use File::EXCL mode" do
@fh = File.new(@file, File::EXCL) @fh = File.new(@file, File::EXCL)
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "raises an Errorno::EEXIST if the file exists when create a new file with File::CREAT|File::EXCL" do it "raises an Errorno::EEXIST if the file exists when create a new file with File::CREAT|File::EXCL" do
@ -91,46 +91,46 @@ describe "File.new" do
it "creates a new file when use File::WRONLY|File::APPEND mode" do it "creates a new file when use File::WRONLY|File::APPEND mode" do
@fh = File.new(@file, File::WRONLY|File::APPEND) @fh = File.new(@file, File::WRONLY|File::APPEND)
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "returns a new File when use File::APPEND mode" do it "returns a new File when use File::APPEND mode" do
@fh = File.new(@file, File::APPEND) @fh = File.new(@file, File::APPEND)
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "returns a new File when use File::RDONLY|File::APPEND mode" do it "returns a new File when use File::RDONLY|File::APPEND mode" do
@fh = File.new(@file, File::RDONLY|File::APPEND) @fh = File.new(@file, File::RDONLY|File::APPEND)
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "returns a new File when use File::RDONLY|File::WRONLY mode" do it "returns a new File when use File::RDONLY|File::WRONLY mode" do
@fh = File.new(@file, File::RDONLY|File::WRONLY) @fh = File.new(@file, File::RDONLY|File::WRONLY)
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "creates a new file when use File::WRONLY|File::TRUNC mode" do it "creates a new file when use File::WRONLY|File::TRUNC mode" do
@fh = File.new(@file, File::WRONLY|File::TRUNC) @fh = File.new(@file, File::WRONLY|File::TRUNC)
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "coerces filename using to_str" do it "coerces filename using to_str" do
name = mock("file") name = mock("file")
name.should_receive(:to_str).and_return(@file) name.should_receive(:to_str).and_return(@file)
@fh = File.new(name, "w") @fh = File.new(name, "w")
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "coerces filename using #to_path" do it "coerces filename using #to_path" do
name = mock("file") name = mock("file")
name.should_receive(:to_path).and_return(@file) name.should_receive(:to_path).and_return(@file)
@fh = File.new(name, "w") @fh = File.new(name, "w")
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "raises a TypeError if the first parameter can't be coerced to a string" do it "raises a TypeError if the first parameter can't be coerced to a string" do

View file

@ -63,40 +63,40 @@ describe "File.open" do
it "opens the file (basic case)" do it "opens the file (basic case)" do
@fh = File.open(@file) @fh = File.open(@file)
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "opens the file with unicode characters" do it "opens the file with unicode characters" do
@fh = File.open(@unicode_path, "w") @fh = File.open(@unicode_path, "w")
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@unicode_path).should == true File.should.exist?(@unicode_path)
end end
it "opens a file when called with a block" do it "opens a file when called with a block" do
File.open(@file) { |fh| } File.open(@file) { |fh| }
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "opens with mode string" do it "opens with mode string" do
@fh = File.open(@file, 'w') @fh = File.open(@file, 'w')
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "opens a file with mode string and block" do it "opens a file with mode string and block" do
File.open(@file, 'w') { |fh| } File.open(@file, 'w') { |fh| }
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "opens a file with mode num" do it "opens a file with mode num" do
@fh = File.open(@file, @flags) @fh = File.open(@file, @flags)
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "opens a file with mode num and block" do it "opens a file with mode num and block" do
File.open(@file, 'w') { |fh| } File.open(@file, 'w') { |fh| }
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "opens a file with mode and permission as nil" do it "opens a file with mode and permission as nil" do
@ -113,7 +113,7 @@ describe "File.open" do
platform_is_not :windows do platform_is_not :windows do
@fh.lstat.mode.to_s(8).should == "100744" @fh.lstat.mode.to_s(8).should == "100744"
end end
File.exist?(@file).should == true File.should.exist?(@file)
end end
# For this test we delete the file first to reset the perms # For this test we delete the file first to reset the perms
@ -124,7 +124,7 @@ describe "File.open" do
platform_is_not :windows do platform_is_not :windows do
File.stat(@file).mode.to_s(8).should == "100755" File.stat(@file).mode.to_s(8).should == "100755"
end end
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "creates the file and returns writable descriptor when called with 'w' mode and r-o permissions" do it "creates the file and returns writable descriptor when called with 'w' mode and r-o permissions" do
@ -162,7 +162,7 @@ describe "File.open" do
fh_copy = File.open(@fh.fileno) fh_copy = File.open(@fh.fileno)
fh_copy.autoclose = false fh_copy.autoclose = false
fh_copy.should be_kind_of(File) fh_copy.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "opens a file that no exists when use File::WRONLY mode" do it "opens a file that no exists when use File::WRONLY mode" do
@ -206,19 +206,19 @@ describe "File.open" do
it "opens a file that no exists when use File::CREAT mode" do it "opens a file that no exists when use File::CREAT mode" do
@fh = File.open(@nonexistent, File::CREAT) { |f| f } @fh = File.open(@nonexistent, File::CREAT) { |f| f }
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "opens a file that no exists when use 'a' mode" do it "opens a file that no exists when use 'a' mode" do
@fh = File.open(@nonexistent, 'a') { |f| f } @fh = File.open(@nonexistent, 'a') { |f| f }
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "opens a file that no exists when use 'w' mode" do it "opens a file that no exists when use 'w' mode" do
@fh = File.open(@nonexistent, 'w') { |f| f } @fh = File.open(@nonexistent, 'w') { |f| f }
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
# Check the grants associated to the different open modes combinations. # Check the grants associated to the different open modes combinations.
@ -365,7 +365,7 @@ describe "File.open" do
it "creates a new file when use File::WRONLY|File::APPEND mode" do it "creates a new file when use File::WRONLY|File::APPEND mode" do
@fh = File.open(@file, File::WRONLY|File::APPEND) @fh = File.open(@file, File::WRONLY|File::APPEND)
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "opens a file when use File::WRONLY|File::APPEND mode" do it "opens a file when use File::WRONLY|File::APPEND mode" do
@ -408,7 +408,7 @@ describe "File.open" do
begin begin
@fh = File.open(@file, File::WRONLY|File::TRUNC) @fh = File.open(@file, File::WRONLY|File::TRUNC)
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
ensure ensure
fh1.close fh1.close
end end
@ -471,13 +471,13 @@ describe "File.open" do
it "opens a file for binary read" do it "opens a file for binary read" do
@fh = File.open(@file, "rb") @fh = File.open(@file, "rb")
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "opens a file for binary write" do it "opens a file for binary write" do
@fh = File.open(@file, "wb") @fh = File.open(@file, "wb")
@fh.should be_kind_of(File) @fh.should be_kind_of(File)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "opens a file for read-write and truncate the file" do it "opens a file for read-write and truncate the file" do
@ -523,10 +523,10 @@ describe "File.open" do
io.read.should == "ruby" io.read.should == "ruby"
Dir["#{dir}/*"].should == [] Dir["#{dir}/*"].should == []
end end
rescue Errno::EOPNOTSUPP, Errno::EINVAL, Errno::EISDIR rescue Errno::EOPNOTSUPP
# EOPNOTSUPP: no support from the filesystem skip "no support from the filesystem"
# EINVAL: presumably bug in glibc rescue Errno::EINVAL, Errno::EISDIR
1.should == 1 skip "presumably bug in glibc"
ensure ensure
rm_r dir rm_r dir
end end

View file

@ -14,11 +14,11 @@ describe "File.rename" do
end end
it "renames a file" do it "renames a file" do
File.exist?(@old).should == true File.should.exist?(@old)
File.exist?(@new).should == false File.should_not.exist?(@new)
File.rename(@old, @new) File.rename(@old, @new)
File.exist?(@old).should == false File.should_not.exist?(@old)
File.exist?(@new).should == true File.should.exist?(@new)
end end
it "raises an Errno::ENOENT if the source does not exist" do it "raises an Errno::ENOENT if the source does not exist" do

View file

@ -68,8 +68,7 @@ describe :file_path, shared: true do
-> { f.send(@method) }.should raise_error(IOError) -> { f.send(@method) }.should raise_error(IOError)
end end
rescue Errno::EOPNOTSUPP, Errno::EINVAL, Errno::EISDIR rescue Errno::EOPNOTSUPP, Errno::EINVAL, Errno::EISDIR
# EOPNOTSUPP: no support from the filesystem skip "no support from the filesystem"
1.should == 1
end end
end end
end end

View file

@ -21,13 +21,13 @@ describe :file_unlink, shared: true do
it "deletes a single file" do it "deletes a single file" do
File.send(@method, @file1).should == 1 File.send(@method, @file1).should == 1
File.exist?(@file1).should == false File.should_not.exist?(@file1)
end end
it "deletes multiple files" do it "deletes multiple files" do
File.send(@method, @file1, @file2).should == 2 File.send(@method, @file1, @file2).should == 2
File.exist?(@file1).should == false File.should_not.exist?(@file1)
File.exist?(@file2).should == false File.should_not.exist?(@file2)
end end
it "raises a TypeError if not passed a String type" do it "raises a TypeError if not passed a String type" do
@ -52,10 +52,10 @@ describe :file_unlink, shared: true do
it "allows deleting an open file with File::SHARE_DELETE" do it "allows deleting an open file with File::SHARE_DELETE" do
path = tmp("share_delete.txt") path = tmp("share_delete.txt")
File.open(path, mode: File::CREAT | File::WRONLY | File::BINARY | File::SHARE_DELETE) do |f| File.open(path, mode: File::CREAT | File::WRONLY | File::BINARY | File::SHARE_DELETE) do |f|
File.exist?(path).should be_true File.should.exist?(path)
File.send(@method, path) File.send(@method, path)
end end
File.exist?(path).should be_false File.should_not.exist?(path)
end end
end end
end end

View file

@ -6,7 +6,7 @@ describe "File.world_readable?" do
it "returns nil if the file does not exist" do it "returns nil if the file does not exist" do
file = rand.to_s + $$.to_s file = rand.to_s + $$.to_s
File.exist?(file).should be_false File.should_not.exist?(file)
File.world_readable?(file).should be_nil File.world_readable?(file).should be_nil
end end
end end

View file

@ -6,7 +6,7 @@ describe "File.world_writable?" do
it "returns nil if the file does not exist" do it "returns nil if the file does not exist" do
file = rand.to_s + $$.to_s file = rand.to_s + $$.to_s
File.exist?(file).should be_false File.should_not.exist?(file)
File.world_writable?(file).should be_nil File.world_writable?(file).should be_nil
end end
end end

View file

@ -82,8 +82,7 @@ describe "IO#advise" do
`uname -r`.chomp `uname -r`.chomp
end end
if (uname.split('.').map(&:to_i) <=> [3,6]) < 0 if (uname.split('.').map(&:to_i) <=> [3,6]) < 0
# [ruby-core:65355] tmpfs is not supported skip "[ruby-core:65355] tmpfs is not supported"
1.should == 1
else else
@io.advise(:willneed).should be_nil @io.advise(:willneed).should be_nil
end end

View file

@ -161,14 +161,14 @@ describe "IO#reopen with a String" do
@io = new_io @name, "w" @io = new_io @name, "w"
@io.reopen(@other_name) @io.reopen(@other_name)
File.exist?(@other_name).should be_true File.should.exist?(@other_name)
end end
it "creates the file if it doesn't exist if the IO is opened in write mode" do it "creates the file if it doesn't exist if the IO is opened in write mode" do
@io = new_io @name, "a" @io = new_io @name, "a"
@io.reopen(@other_name) @io.reopen(@other_name)
File.exist?(@other_name).should be_true File.should.exist?(@other_name)
end end
end end

View file

@ -24,9 +24,9 @@ describe :io_binwrite, shared: true do
it "creates a file if missing" do it "creates a file if missing" do
fn = @filename + "xxx" fn = @filename + "xxx"
begin begin
File.exist?(fn).should be_false File.should_not.exist?(fn)
IO.send(@method, fn, "test") IO.send(@method, fn, "test")
File.exist?(fn).should be_true File.should.exist?(fn)
ensure ensure
rm_r fn rm_r fn
end end
@ -35,9 +35,9 @@ describe :io_binwrite, shared: true do
it "creates file if missing even if offset given" do it "creates file if missing even if offset given" do
fn = @filename + "xxx" fn = @filename + "xxx"
begin begin
File.exist?(fn).should be_false File.should_not.exist?(fn)
IO.send(@method, fn, "test", 0) IO.send(@method, fn, "test", 0)
File.exist?(fn).should be_true File.should.exist?(fn)
ensure ensure
rm_r fn rm_r fn
end end

View file

@ -7,8 +7,7 @@ describe :io_tty, shared: true do
# check to enabled tty # check to enabled tty
File.open('/dev/tty') {} File.open('/dev/tty') {}
rescue Errno::ENXIO rescue Errno::ENXIO
# workaround for not configured environment like OS X skip "workaround for not configured environment like OS X"
1.should == 1
else else
File.open('/dev/tty') { |f| f.send(@method) }.should == true File.open('/dev/tty') { |f| f.send(@method) }.should == true
end end

View file

@ -68,8 +68,10 @@ describe 'IO#write_nonblock' do
context "when exception option is set to false" do context "when exception option is set to false" do
it "returns :wait_writable when the operation would block" do it "returns :wait_writable when the operation would block" do
loop { break if @write.write_nonblock("a" * 10_000, exception: false) == :wait_writable } loop {
1.should == 1 break if @write.write_nonblock("a" * 10_000, exception: false) == :wait_writable
}
@write.write_nonblock("a" * 10_000, exception: false).should == :wait_writable
end end
end end

View file

@ -13,7 +13,7 @@ describe 'Kernel#caller_locations' do
it 'returns an Array of caller locations using a custom offset' do it 'returns an Array of caller locations using a custom offset' do
locations = KernelSpecs::CallerLocationsTest.locations(2) locations = KernelSpecs::CallerLocationsTest.locations(2)
locations[0].absolute_path.end_with?('mspec.rb').should == true locations[0].absolute_path.should.end_with?('mspec.rb')
end end
it 'returns an Array of caller locations using a custom limit' do it 'returns an Array of caller locations using a custom limit' do

View file

@ -20,7 +20,7 @@ describe :kernel_require_basic, shared: true do
it "raises a LoadError if the file does not exist" do it "raises a LoadError if the file does not exist" do
path = File.expand_path "nonexistent.rb", CODE_LOADING_DIR path = File.expand_path "nonexistent.rb", CODE_LOADING_DIR
File.exist?(path).should be_false File.should_not.exist?(path)
-> { @object.send(@method, path) }.should raise_error(LoadError) -> { @object.send(@method, path) }.should raise_error(LoadError)
ScratchPad.recorded.should == [] ScratchPad.recorded.should == []
end end
@ -41,7 +41,7 @@ describe :kernel_require_basic, shared: true do
end end
it "raises a LoadError" do it "raises a LoadError" do
File.exist?(@path).should be_true File.should.exist?(@path)
-> { @object.send(@method, @path) }.should raise_error(LoadError) -> { @object.send(@method, @path) }.should raise_error(LoadError)
end end
end end
@ -247,7 +247,7 @@ describe :kernel_require, shared: true do
describe "(file extensions)" do describe "(file extensions)" do
it "loads a .rb extensioned file when passed a non-extensioned path" do it "loads a .rb extensioned file when passed a non-extensioned path" do
path = File.expand_path "load_fixture", CODE_LOADING_DIR path = File.expand_path "load_fixture", CODE_LOADING_DIR
File.exist?(path).should be_true File.should.exist?(path)
@object.require(path).should be_true @object.require(path).should be_true
ScratchPad.recorded.should == [:loaded] ScratchPad.recorded.should == [:loaded]
end end
@ -271,7 +271,7 @@ describe :kernel_require, shared: true do
it "loads a .rb extensioned file when passed a non-.rb extensioned path" do it "loads a .rb extensioned file when passed a non-.rb extensioned path" do
path = File.expand_path "load_fixture.ext", CODE_LOADING_DIR path = File.expand_path "load_fixture.ext", CODE_LOADING_DIR
File.exist?(path).should be_true File.should.exist?(path)
@object.require(path).should be_true @object.require(path).should be_true
ScratchPad.recorded.should == [:loaded] ScratchPad.recorded.should == [:loaded]
end end

View file

@ -388,8 +388,8 @@ describe "String#dump" do
end end
it "includes .force_encoding(name) if the encoding isn't ASCII compatible" do it "includes .force_encoding(name) if the encoding isn't ASCII compatible" do
"\u{876}".encode('utf-16be').dump.end_with?(".force_encoding(\"UTF-16BE\")").should be_true "\u{876}".encode('utf-16be').dump.should.end_with?(".force_encoding(\"UTF-16BE\")")
"\u{876}".encode('utf-16le').dump.end_with?(".force_encoding(\"UTF-16LE\")").should be_true "\u{876}".encode('utf-16le').dump.should.end_with?(".force_encoding(\"UTF-16LE\")")
end end
it "keeps origin encoding" do it "keeps origin encoding" do

View file

@ -5,33 +5,33 @@ require_relative 'fixtures/classes'
describe "String#end_with?" do describe "String#end_with?" do
it "returns true only if ends match" do it "returns true only if ends match" do
s = "hello" s = "hello"
s.end_with?('o').should be_true s.should.end_with?('o')
s.end_with?('llo').should be_true s.should.end_with?('llo')
end end
it 'returns false if the end does not match' do it 'returns false if the end does not match' do
s = 'hello' s = 'hello'
s.end_with?('ll').should be_false s.should_not.end_with?('ll')
end end
it "returns true if the search string is empty" do it "returns true if the search string is empty" do
"hello".end_with?("").should be_true "hello".should.end_with?("")
"".end_with?("").should be_true "".should.end_with?("")
end end
it "returns true only if any ending match" do it "returns true only if any ending match" do
"hello".end_with?('x', 'y', 'llo', 'z').should be_true "hello".should.end_with?('x', 'y', 'llo', 'z')
end end
it "converts its argument using :to_str" do it "converts its argument using :to_str" do
s = "hello" s = "hello"
find = mock('o') find = mock('o')
find.should_receive(:to_str).and_return("o") find.should_receive(:to_str).and_return("o")
s.end_with?(find).should be_true s.should.end_with?(find)
end end
it "ignores arguments not convertible to string" do it "ignores arguments not convertible to string" do
"hello".end_with?().should be_false "hello".should_not.end_with?()
-> { "hello".end_with?(1) }.should raise_error(TypeError) -> { "hello".end_with?(1) }.should raise_error(TypeError)
-> { "hello".end_with?(["o"]) }.should raise_error(TypeError) -> { "hello".end_with?(["o"]) }.should raise_error(TypeError)
-> { "hello".end_with?(1, nil, "o") }.should raise_error(TypeError) -> { "hello".end_with?(1, nil, "o") }.should raise_error(TypeError)
@ -40,11 +40,11 @@ describe "String#end_with?" do
it "uses only the needed arguments" do it "uses only the needed arguments" do
find = mock('h') find = mock('h')
find.should_not_receive(:to_str) find.should_not_receive(:to_str)
"hello".end_with?("o",find).should be_true "hello".should.end_with?("o",find)
end end
it "works for multibyte strings" do it "works for multibyte strings" do
"céréale".end_with?("réale").should be_true "céréale".should.end_with?("réale")
end end
it "raises an Encoding::CompatibilityError if the encodings are incompatible" do it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
@ -53,5 +53,4 @@ describe "String#end_with?" do
"あれ".end_with?(pat) "あれ".end_with?(pat)
end.should raise_error(Encoding::CompatibilityError) end.should raise_error(Encoding::CompatibilityError)
end end
end end

View file

@ -5,29 +5,29 @@ require_relative 'fixtures/classes'
describe "String#start_with?" do describe "String#start_with?" do
it "returns true only if beginning match" do it "returns true only if beginning match" do
s = "hello" s = "hello"
s.start_with?('h').should be_true s.should.start_with?('h')
s.start_with?('hel').should be_true s.should.start_with?('hel')
s.start_with?('el').should be_false s.should_not.start_with?('el')
end end
it "returns true only if any beginning match" do it "returns true only if any beginning match" do
"hello".start_with?('x', 'y', 'he', 'z').should be_true "hello".should.start_with?('x', 'y', 'he', 'z')
end end
it "returns true if the search string is empty" do it "returns true if the search string is empty" do
"hello".start_with?("").should be_true "hello".should.start_with?("")
"".start_with?("").should be_true "".should.start_with?("")
end end
it "converts its argument using :to_str" do it "converts its argument using :to_str" do
s = "hello" s = "hello"
find = mock('h') find = mock('h')
find.should_receive(:to_str).and_return("h") find.should_receive(:to_str).and_return("h")
s.start_with?(find).should be_true s.should.start_with?(find)
end end
it "ignores arguments not convertible to string" do it "ignores arguments not convertible to string" do
"hello".start_with?().should be_false "hello".should_not.start_with?()
-> { "hello".start_with?(1) }.should raise_error(TypeError) -> { "hello".start_with?(1) }.should raise_error(TypeError)
-> { "hello".start_with?(["h"]) }.should raise_error(TypeError) -> { "hello".start_with?(["h"]) }.should raise_error(TypeError)
-> { "hello".start_with?(1, nil, "h") }.should raise_error(TypeError) -> { "hello".start_with?(1, nil, "h") }.should raise_error(TypeError)
@ -36,29 +36,29 @@ describe "String#start_with?" do
it "uses only the needed arguments" do it "uses only the needed arguments" do
find = mock('h') find = mock('h')
find.should_not_receive(:to_str) find.should_not_receive(:to_str)
"hello".start_with?("h",find).should be_true "hello".should.start_with?("h",find)
end end
it "works for multibyte strings" do it "works for multibyte strings" do
"céréale".start_with?("cér").should be_true "céréale".should.start_with?("cér")
end end
ruby_version_is "2.5" do ruby_version_is "2.5" do
it "supports regexps" do it "supports regexps" do
regexp = /[h1]/ regexp = /[h1]/
"hello".start_with?(regexp).should be_true "hello".should.start_with?(regexp)
"1337".start_with?(regexp).should be_true "1337".should.start_with?(regexp)
"foxes are 1337".start_with?(regexp).should be_false "foxes are 1337".should_not.start_with?(regexp)
"chunky\n12bacon".start_with?(/12/).should be_false "chunky\n12bacon".should_not.start_with?(/12/)
end end
it "supports regexps with ^ and $ modifiers" do it "supports regexps with ^ and $ modifiers" do
regexp1 = /^\d{2}/ regexp1 = /^\d{2}/
regexp2 = /\d{2}$/ regexp2 = /\d{2}$/
"12test".start_with?(regexp1).should be_true "12test".should.start_with?(regexp1)
"test12".start_with?(regexp1).should be_false "test12".should_not.start_with?(regexp1)
"12test".start_with?(regexp2).should be_false "12test".should_not.start_with?(regexp2)
"test12".start_with?(regexp2).should be_false "test12".should_not.start_with?(regexp2)
end end
it "sets Regexp.last_match if it returns true" do it "sets Regexp.last_match if it returns true" do

View file

@ -31,7 +31,7 @@ describe "Logger::LogDevice#new" do
l.write("Test message") l.write("Test message")
l.close l.close
File.exist?(path).should be_true File.should.exist?(path)
File.open(path) do |f| File.open(path) do |f|
f.readlines.should_not be_empty f.readlines.should_not be_empty
end end

View file

@ -46,8 +46,8 @@ describe "Logger#new" do
l.add Logger::WARN, "foo" l.add Logger::WARN, "foo"
l.add Logger::WARN, "bar" l.add Logger::WARN, "bar"
File.exist?(path).should be_true File.should.exist?(path)
File.exist?(path + ".0").should be_true File.should.exist?(path + ".0")
# first line will be a comment so we'll have to skip it. # first line will be a comment so we'll have to skip it.
f = File.open(path) f = File.open(path)
@ -108,7 +108,7 @@ describe "Logger#new" do
shifted_path = "#{path}.#{now.strftime(shift_period_suffix)}" shifted_path = "#{path}.#{now.strftime(shift_period_suffix)}"
File.exist?(shifted_path).should == true File.should.exist?(shifted_path)
logger.close logger.close

View file

@ -14,13 +14,13 @@ describe 'RbConfig::CONFIG' do
it "['rubylibdir'] returns the directory containing Ruby standard libraries" do it "['rubylibdir'] returns the directory containing Ruby standard libraries" do
rubylibdir = RbConfig::CONFIG['rubylibdir'] rubylibdir = RbConfig::CONFIG['rubylibdir']
File.directory?(rubylibdir).should == true File.directory?(rubylibdir).should == true
File.exist?("#{rubylibdir}/fileutils.rb").should == true File.should.exist?("#{rubylibdir}/fileutils.rb")
end end
it "['archdir'] returns the directory containing standard libraries C extensions" do it "['archdir'] returns the directory containing standard libraries C extensions" do
archdir = RbConfig::CONFIG['archdir'] archdir = RbConfig::CONFIG['archdir']
File.directory?(archdir).should == true File.directory?(archdir).should == true
File.exist?("#{archdir}/etc.#{RbConfig::CONFIG['DLEXT']}").should == true File.should.exist?("#{archdir}/etc.#{RbConfig::CONFIG['DLEXT']}")
end end
end end
end end

View file

@ -20,16 +20,13 @@ describe "Gem.bin_path" do
default_specifications_dir = Gem::Specification.default_specifications_dir default_specifications_dir = Gem::Specification.default_specifications_dir
end end
if Dir.exist?(default_specifications_dir) skip "Could not find the default gemspecs" unless Dir.exist?(default_specifications_dir)
Gem::Specification.each_spec([default_specifications_dir]) do |spec|
spec.executables.each do |exe| Gem::Specification.each_spec([default_specifications_dir]) do |spec|
path = Gem.bin_path(spec.name, exe) spec.executables.each do |exe|
File.should.exist?(path) path = Gem.bin_path(spec.name, exe)
end File.should.exist?(path)
end end
else
# non-installed MRI, there are no default gemspecs
1.should == 1
end end
end end
end end

View file

@ -18,7 +18,7 @@ describe "Tempfile#close when passed no argument or [false]" do
it "does not unlink self" do it "does not unlink self" do
path = @tempfile.path path = @tempfile.path
@tempfile.close @tempfile.close
File.exist?(path).should be_true File.should.exist?(path)
end end
end end
@ -35,7 +35,7 @@ describe "Tempfile#close when passed [true]" do
it "unlinks self" do it "unlinks self" do
path = @tempfile.path path = @tempfile.path
@tempfile.close(true) @tempfile.close(true)
File.exist?(path).should be_false File.should_not.exist?(path)
end end
end end
@ -52,6 +52,6 @@ describe "Tempfile#close!" do
it "unlinks self" do it "unlinks self" do
path = @tempfile.path path = @tempfile.path
@tempfile.close! @tempfile.close!
File.exist?(path).should be_false File.should_not.exist?(path)
end end
end end

View file

@ -12,7 +12,7 @@ describe "Tempfile#initialize" do
it "opens a new tempfile with the passed name in the passed directory" do it "opens a new tempfile with the passed name in the passed directory" do
@tempfile.send(:initialize, "basename", tmp("")) @tempfile.send(:initialize, "basename", tmp(""))
File.exist?(@tempfile.path).should be_true File.should.exist?(@tempfile.path)
tmpdir = tmp("") tmpdir = tmp("")
path = @tempfile.path path = @tempfile.path

View file

@ -7,6 +7,6 @@ describe :tempfile_unlink, shared: true do
@tempfile.close @tempfile.close
path = @tempfile.path path = @tempfile.path
@tempfile.send(@method) @tempfile.send(@method)
File.exist?(path).should be_false File.should_not.exist?(path)
end end
end end

View file

@ -39,7 +39,7 @@ describe "Dir.mktmpdir when passed a block" do
Dir.mktmpdir do |path| Dir.mktmpdir do |path|
@tmpdir = path @tmpdir = path
called = true called = true
path.start_with?(@real_tmp_root).should be_true path.should.start_with?(@real_tmp_root)
end end
called.should be_true called.should be_true
end end

View file

@ -26,8 +26,7 @@ describe :file_grpowned, shared: true do
@object.send(@method, @file).should == true @object.send(@method, @file).should == true
else else
# No supplementary groups skip "No supplementary groups"
1.should == 1
end end
end end
end end

View file

@ -37,7 +37,7 @@ describe :file_world_readable, shared: true do
it "returns a Fixnum if the file is a directory and chmod 644" do it "returns a Fixnum if the file is a directory and chmod 644" do
dir = rand().to_s + '-ww' dir = rand().to_s + '-ww'
Dir.mkdir(dir) Dir.mkdir(dir)
Dir.exist?(dir).should be_true Dir.should.exist?(dir)
File.chmod(0644, dir) File.chmod(0644, dir)
@object.world_readable?(dir).should be_an_instance_of(Fixnum) @object.world_readable?(dir).should be_an_instance_of(Fixnum)
Dir.rmdir(dir) Dir.rmdir(dir)

View file

@ -36,7 +36,7 @@ describe :file_world_writable, shared: true do
it "returns a Fixnum if the file is a directory and chmod 777" do it "returns a Fixnum if the file is a directory and chmod 777" do
dir = rand().to_s + '-ww' dir = rand().to_s + '-ww'
Dir.mkdir(dir) Dir.mkdir(dir)
Dir.exist?(dir).should be_true Dir.should.exist?(dir)
File.chmod(0777, dir) File.chmod(0777, dir)
@object.world_writable?(dir).should be_an_instance_of(Fixnum) @object.world_writable?(dir).should be_an_instance_of(Fixnum)
Dir.rmdir(dir) Dir.rmdir(dir)

View file

@ -60,7 +60,7 @@ describe :process_fork, shared: true do
else else
Process.waitpid(child_id) Process.waitpid(child_id)
end end
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "runs a block in a child process" do it "runs a block in a child process" do
@ -69,7 +69,7 @@ describe :process_fork, shared: true do
Process.exit! Process.exit!
} }
Process.waitpid(pid) Process.waitpid(pid)
File.exist?(@file).should == true File.should.exist?(@file)
end end
it "marks threads from the parent as killed" do it "marks threads from the parent as killed" do