How to use assert_file method of Platform Package

Best Selenium code snippet using Platform.assert_file

test_file_exhaustive.rb

Source:test_file_exhaustive.rb Github

copy

Full Screen

...111 def test_stat_dotted_prefix112 Dir.mktmpdir do |dir|113 prefix = File.join(dir, "...a")114 Dir.mkdir(prefix)115 assert_file.exist?(prefix)116 assert_nothing_raised { File.stat(prefix) }117 Dir.chdir(dir) do118 assert_nothing_raised { File.stat(File.basename(prefix)) }119 end120 end121 end if /mswin|mingw|cygwin/ =~ RUBY_PLATFORM122 def test_directory_p123 assert_file.directory?(@dir)124 assert_file.not_directory?(@dir+"/...")125 assert_file.not_directory?(@file)126 assert_file.not_directory?(@nofile)127 end128 def test_pipe_p ## xxx129 assert_file.not_pipe?(@dir)130 assert_file.not_pipe?(@file)131 assert_file.not_pipe?(@nofile)132 end133 def test_symlink_p134 assert_file.not_symlink?(@dir)135 assert_file.not_symlink?(@file)136 assert_file.symlink?(@symlinkfile) if @symlinkfile137 assert_file.not_symlink?(@hardlinkfile) if @hardlinkfile138 assert_file.not_symlink?(@nofile)139 end140 def test_socket_p ## xxx141 assert_file.not_socket?(@dir)142 assert_file.not_socket?(@file)143 assert_file.not_socket?(@nofile)144 end145 def test_blockdev_p ## xxx146 assert_file.not_blockdev?(@dir)147 assert_file.not_blockdev?(@file)148 assert_file.not_blockdev?(@nofile)149 end150 def test_chardev_p ## xxx151 assert_file.not_chardev?(@dir)152 assert_file.not_chardev?(@file)153 assert_file.not_chardev?(@nofile)154 end155 def test_exist_p156 assert_file.exist?(@dir)157 assert_file.exist?(@file)158 assert_file.not_exist?(@nofile)159 end160 def test_readable_p161 return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM162 return if Process.euid == 0163 File.chmod(0200, @file)164 assert_file.not_readable?(@file)165 File.chmod(0600, @file)166 assert_file.readable?(@file)167 assert_file.not_readable?(@nofile)168 end169 def test_readable_real_p170 return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM171 return if Process.euid == 0172 File.chmod(0200, @file)173 assert_file.not_readable_real?(@file)174 File.chmod(0600, @file)175 assert_file.readable_real?(@file)176 assert_file.not_readable_real?(@nofile)177 end178 def test_world_readable_p179 return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM180 File.chmod(0006, @file)181 assert_file.world_readable?(@file)182 File.chmod(0060, @file)183 assert_file.not_world_readable?(@file)184 File.chmod(0600, @file)185 assert_file.not_world_readable?(@file)186 assert_file.not_world_readable?(@nofile)187 end188 def test_writable_p189 return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM190 return if Process.euid == 0191 File.chmod(0400, @file)192 assert_file.not_writable?(@file)193 File.chmod(0600, @file)194 assert_file.writable?(@file)195 assert_file.not_writable?(@nofile)196 end197 def test_writable_real_p198 return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM199 return if Process.euid == 0200 File.chmod(0400, @file)201 assert_file.not_writable_real?(@file)202 File.chmod(0600, @file)203 assert_file.writable_real?(@file)204 assert_file.not_writable_real?(@nofile)205 end206 def test_world_writable_p207 return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM208 File.chmod(0006, @file)209 assert_file.world_writable?(@file)210 File.chmod(0060, @file)211 assert_file.not_world_writable?(@file)212 File.chmod(0600, @file)213 assert_file.not_world_writable?(@file)214 assert_file.not_world_writable?(@nofile)215 end216 def test_executable_p217 return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM218 File.chmod(0100, @file)219 assert_file.executable?(@file)220 File.chmod(0600, @file)221 assert_file.not_executable?(@file)222 assert_file.not_executable?(@nofile)223 end224 def test_executable_real_p225 return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM226 File.chmod(0100, @file)227 assert_file.executable_real?(@file)228 File.chmod(0600, @file)229 assert_file.not_executable_real?(@file)230 assert_file.not_executable_real?(@nofile)231 end232 def test_file_p233 assert_file.not_file?(@dir)234 assert_file.file?(@file)235 assert_file.not_file?(@nofile)236 end237 def test_zero_p238 assert_nothing_raised { File.zero?(@dir) }239 assert_file.not_zero?(@file)240 assert_file.zero?(@zerofile)241 assert_file.not_zero?(@nofile)242 end243 def test_size_p244 assert_nothing_raised { File.size?(@dir) }245 assert_equal(3, File.size?(@file))246 assert_file.not_size?(@zerofile)247 assert_file.not_size?(@nofile)248 end249 def test_owned_p ## xxx250 return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM251 assert_file.owned?(@file)252 assert_file.grpowned?(@file)253 end254 def test_suid_sgid_sticky ## xxx255 assert_file.not_setuid?(@file)256 assert_file.not_setgid?(@file)257 assert_file.not_sticky?(@file)258 end259 def test_identical_p260 assert_file.identical?(@file, @file)261 assert_file.not_identical?(@file, @zerofile)262 assert_file.not_identical?(@file, @nofile)263 assert_file.not_identical?(@nofile, @file)264 end265 def test_s_size266 assert_integer(File.size(@dir))267 assert_equal(3, File.size(@file))268 assert_equal(0, File.size(@zerofile))269 assert_raise(Errno::ENOENT) { File.size(@nofile) }270 end271 def test_ftype272 assert_equal("directory", File.ftype(@dir))273 assert_equal("file", File.ftype(@file))274 assert_equal("link", File.ftype(@symlinkfile)) if @symlinkfile275 assert_equal("file", File.ftype(@hardlinkfile)) if @hardlinkfile276 assert_raise(Errno::ENOENT) { File.ftype(@nofile) }277 end278 def test_atime279 t1 = File.atime(@file)280 t2 = File.open(@file) {|f| f.atime}281 assert_kind_of(Time, t1)282 assert_kind_of(Time, t2)283 assert_equal(t1, t2)284 assert_raise(Errno::ENOENT) { File.atime(@nofile) }285 end286 def test_mtime287 t1 = File.mtime(@file)288 t2 = File.open(@file) {|f| f.mtime}289 assert_kind_of(Time, t1)290 assert_kind_of(Time, t2)291 assert_equal(t1, t2)292 assert_raise(Errno::ENOENT) { File.mtime(@nofile) }293 end294 def test_ctime295 t1 = File.ctime(@file)296 t2 = File.open(@file) {|f| f.ctime}297 assert_kind_of(Time, t1)298 assert_kind_of(Time, t2)299 assert_equal(t1, t2)300 assert_raise(Errno::ENOENT) { File.ctime(@nofile) }301 end302 def test_chmod303 return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM304 assert_equal(1, File.chmod(0444, @file))305 assert_equal(0444, File.stat(@file).mode % 01000)306 assert_equal(0, File.open(@file) {|f| f.chmod(0222)})307 assert_equal(0222, File.stat(@file).mode % 01000)308 File.chmod(0600, @file)309 assert_raise(Errno::ENOENT) { File.chmod(0600, @nofile) }310 end311 def test_lchmod312 return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM313 assert_equal(1, File.lchmod(0444, @file))314 assert_equal(0444, File.stat(@file).mode % 01000)315 File.lchmod(0600, @file)316 assert_raise(Errno::ENOENT) { File.lchmod(0600, @nofile) }317 rescue NotImplementedError318 end319 def test_chown ## xxx320 end321 def test_lchown ## xxx322 end323 def test_symlink324 return unless @symlinkfile325 assert_equal("link", File.ftype(@symlinkfile))326 assert_raise(Errno::EEXIST) { File.symlink(@file, @file) }327 end328 def test_utime329 t = Time.local(2000)330 File.utime(t + 1, t + 2, @zerofile)331 assert_equal(t + 1, File.atime(@zerofile))332 assert_equal(t + 2, File.mtime(@zerofile))333 end334 def test_hardlink335 return unless @hardlinkfile336 assert_equal("file", File.ftype(@hardlinkfile))337 assert_raise(Errno::EEXIST) { File.link(@file, @file) }338 end339 def test_readlink340 return unless @symlinkfile341 assert_equal(@file, File.readlink(@symlinkfile))342 assert_raise(Errno::EINVAL) { File.readlink(@file) }343 assert_raise(Errno::ENOENT) { File.readlink(@nofile) }344 if fs = Encoding.find("filesystem")345 assert_equal(fs, File.readlink(@symlinkfile).encoding)346 end347 rescue NotImplementedError348 end349 def test_readlink_long_path350 return unless @symlinkfile351 bug9157 = '[ruby-core:58592] [Bug #9157]'352 assert_separately(["-", @symlinkfile, bug9157], <<-"end;")353 symlinkfile, bug9157 = *ARGV354 100.step(1000, 100) do |n|355 File.unlink(symlinkfile)356 link = "foo"*n357 begin358 File.symlink(link, symlinkfile)359 rescue Errno::ENAMETOOLONG360 break361 end362 assert_equal(link, File.readlink(symlinkfile), bug9157)363 end364 end;365 end366 def test_unlink367 assert_equal(1, File.unlink(@file))368 make_file("foo", @file)369 assert_raise(Errno::ENOENT) { File.unlink(@nofile) }370 end371 def test_rename372 assert_equal(0, File.rename(@file, @nofile))373 assert_file.not_exist?(@file)374 assert_file.exist?(@nofile)375 assert_equal(0, File.rename(@nofile, @file))376 assert_raise(Errno::ENOENT) { File.rename(@nofile, @file) }377 end378 def test_umask379 return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM380 prev = File.umask(0777)381 assert_equal(0777, File.umask)382 open(@nofile, "w") { }383 assert_equal(0, File.stat(@nofile).mode % 01000)384 File.unlink(@nofile)385 assert_equal(0777, File.umask(prev))386 assert_raise(ArgumentError) { File.umask(0, 1, 2) }387 end388 def test_expand_path389 assert_equal(@file, File.expand_path(File.basename(@file), File.dirname(@file)))390 if /cygwin|mingw|mswin|bccwin/ =~ RUBY_PLATFORM391 assert_equal(@file, File.expand_path(@file + " "))392 assert_equal(@file, File.expand_path(@file + "."))393 assert_equal(@file, File.expand_path(@file + "::$DATA"))394 assert_match(/\Ac:\//i, File.expand_path('c:'), '[ruby-core:31591]')395 assert_match(/\Ac:\//i, File.expand_path('c:foo', 'd:/bar'))396 assert_match(%r'\Ac:/bar/foo\z'i, File.expand_path('c:foo', 'c:/bar'))397 end398 if DRIVE399 assert_match(%r"\Az:/foo\z"i, File.expand_path('/foo', "z:/bar"))400 assert_match(%r"\A//host/share/foo\z"i, File.expand_path('/foo', "//host/share/bar"))401 assert_match(%r"\A#{DRIVE}/foo\z"i, File.expand_path('/foo'))402 else403 assert_equal("/foo", File.expand_path('/foo'))404 end405 end406 def test_expand_path_encoding407 drive = (DRIVE ? 'C:' : '')408 if Encoding.find("filesystem") == Encoding::CP1251409 a = "#{drive}/\u3042\u3044\u3046\u3048\u304a".encode("cp932")410 else411 a = "#{drive}/\u043f\u0440\u0438\u0432\u0435\u0442".encode("cp1251")412 end413 assert_equal(a, File.expand_path(a))414 a = "#{drive}/\225\\\\"415 if File::ALT_SEPARATOR == '\\'416 [%W"cp437 #{drive}/\225", %W"cp932 #{drive}/\225\\"]417 else418 [["cp437", a], ["cp932", a]]419 end.each do |cp, expected|420 assert_equal(expected.force_encoding(cp), File.expand_path(a.dup.force_encoding(cp)), cp)421 end422 path = "\u3042\u3044\u3046\u3048\u304a".encode("EUC-JP")423 assert_equal("#{Dir.pwd}/#{path}".encode("CP932"), File.expand_path(path).encode("CP932"))424 path = "\u3042\u3044\u3046\u3048\u304a".encode("CP51932")425 assert_equal("#{Dir.pwd}/#{path}", File.expand_path(path))426 assert_incompatible_encoding {|d| File.expand_path(d)}427 end428 def test_expand_path_encoding_filesystem429 home = ENV["HOME"]430 ENV["HOME"] = "#{DRIVE}/UserHome"431 path = "~".encode("US-ASCII")432 dir = "C:/".encode("IBM437")433 fs = Encoding.find("filesystem")434 assert_equal fs, File.expand_path(path).encoding435 assert_equal fs, File.expand_path(path, dir).encoding436 ensure437 ENV["HOME"] = home438 end439 UnknownUserHome = "~foo_bar_baz_unknown_user_wahaha".freeze440 def test_expand_path_home441 assert_kind_of(String, File.expand_path("~")) if ENV["HOME"]442 assert_raise(ArgumentError) { File.expand_path(UnknownUserHome) }443 assert_raise(ArgumentError) { File.expand_path(UnknownUserHome, "/") }444 begin445 bug3630 = '[ruby-core:31537]'446 home = ENV["HOME"]447 home_drive = ENV["HOMEDRIVE"]448 home_path = ENV["HOMEPATH"]449 user_profile = ENV["USERPROFILE"]450 ENV["HOME"] = nil451 ENV["HOMEDRIVE"] = nil452 ENV["HOMEPATH"] = nil453 ENV["USERPROFILE"] = nil454 assert_raise(ArgumentError) { File.expand_path("~") }455 ENV["HOME"] = "~"456 assert_raise(ArgumentError, bug3630) { File.expand_path("~") }457 ENV["HOME"] = "."458 assert_raise(ArgumentError, bug3630) { File.expand_path("~") }459 ensure460 ENV["HOME"] = home461 ENV["HOMEDRIVE"] = home_drive462 ENV["HOMEPATH"] = home_path463 ENV["USERPROFILE"] = user_profile464 end465 end466 def test_expand_path_home_dir_string467 home = ENV["HOME"]468 new_home = "#{DRIVE}/UserHome"469 ENV["HOME"] = new_home470 bug8034 = "[ruby-core:53168]"471 assert_equal File.join(new_home, "foo"), File.expand_path("foo", "~"), bug8034472 assert_equal File.join(new_home, "bar", "foo"), File.expand_path("foo", "~/bar"), bug8034473 assert_raise(ArgumentError) { File.expand_path(".", UnknownUserHome) }474 assert_nothing_raised(ArgumentError) { File.expand_path("#{DRIVE}/", UnknownUserHome) }475 ensure476 ENV["HOME"] = home477 end478 if /mswin|mingw/ =~ RUBY_PLATFORM479 def test_expand_path_home_memory_leak_in_path480 assert_no_memory_leak_at_expand_path_home('', 'in path')481 end482 def test_expand_path_home_memory_leak_in_base483 assert_no_memory_leak_at_expand_path_home('".",', 'in base')484 end485 def assert_no_memory_leak_at_expand_path_home(arg, message)486 prep = 'ENV["HOME"] = "foo"*100'487 assert_no_memory_leak([], prep, <<-TRY, "memory leaked at non-absolute home #{message}")488 10000.times do489 begin490 File.expand_path(#{arg}"~/a")491 rescue ArgumentError => e492 next493 ensure494 abort("ArgumentError (non-absolute home) expected") unless e495 end496 end497 GC.start498 TRY499 end500 end501 def test_expand_path_remove_trailing_alternative_data502 assert_equal File.join(@rootdir, "aaa"), File.expand_path("#{@rootdir}/aaa::$DATA")503 assert_equal File.join(@rootdir, "aa:a"), File.expand_path("#{@rootdir}/aa:a:$DATA")504 assert_equal File.join(@rootdir, "aaa:$DATA"), File.expand_path("#{@rootdir}/aaa:$DATA")505 end if DRIVE506 def test_expand_path_resolve_empty_string_current_directory507 assert_equal(Dir.pwd, File.expand_path(""))508 end509 def test_expand_path_resolve_dot_current_directory510 assert_equal(Dir.pwd, File.expand_path("."))511 end512 def test_expand_path_resolve_file_name_relative_current_directory513 assert_equal(File.join(Dir.pwd, "foo"), File.expand_path("foo"))514 end515 def test_ignore_nil_dir_string516 assert_equal(File.join(Dir.pwd, "foo"), File.expand_path("foo", nil))517 end518 def test_expand_path_resolve_file_name_and_dir_string_relative519 assert_equal(File.join(Dir.pwd, "bar", "foo"),520 File.expand_path("foo", "bar"))521 end522 def test_expand_path_cleanup_dots_file_name523 bug = "[ruby-talk:18512]"524 assert_equal(File.join(Dir.pwd, ".a"), File.expand_path(".a"), bug)525 assert_equal(File.join(Dir.pwd, "..a"), File.expand_path("..a"), bug)526 if DRIVE527 # cleanup dots only on Windows528 assert_equal(File.join(Dir.pwd, "a"), File.expand_path("a."), bug)529 assert_equal(File.join(Dir.pwd, "a"), File.expand_path("a.."), bug)530 else531 assert_equal(File.join(Dir.pwd, "a."), File.expand_path("a."), bug)532 assert_equal(File.join(Dir.pwd, "a.."), File.expand_path("a.."), bug)533 end534 end535 def test_expand_path_converts_a_pathname_to_an_absolute_pathname_using_a_complete_path536 assert_equal(@dir, File.expand_path("", "#{@dir}"))537 assert_equal(File.join(@dir, "a"), File.expand_path("a", "#{@dir}"))538 assert_equal(File.join(@dir, "a"), File.expand_path("../a", "#{@dir}/xxx"))539 assert_equal(@rootdir, File.expand_path(".", "#{@rootdir}"))540 end541 def test_expand_path_ignores_supplied_dir_if_path_contains_a_drive_letter542 assert_equal(@rootdir, File.expand_path(@rootdir, "D:/"))543 end if DRIVE544 def test_expand_path_removes_trailing_slashes_from_absolute_path545 assert_equal(File.join(@rootdir, "foo"), File.expand_path("#{@rootdir}foo/"))546 assert_equal(File.join(@rootdir, "foo.rb"), File.expand_path("#{@rootdir}foo.rb/"))547 end548 def test_expand_path_removes_trailing_spaces_from_absolute_path549 assert_equal(File.join(@rootdir, "a"), File.expand_path("#{@rootdir}a "))550 end if DRIVE551 def test_expand_path_converts_a_pathname_which_starts_with_a_slash_using_dir_s_drive552 assert_match(%r"\Az:/foo\z"i, File.expand_path('/foo', "z:/bar"))553 end if DRIVE554 def test_expand_path_converts_a_pathname_which_starts_with_a_slash_and_unc_pathname555 assert_equal("//foo", File.expand_path('//foo', "//bar"))556 assert_equal("//bar/foo", File.expand_path('/foo', "//bar"))557 assert_equal("//foo", File.expand_path('//foo', "/bar"))558 end if DRIVE559 def test_expand_path_converts_a_dot_with_unc_dir560 assert_equal("//", File.expand_path('.', "//"))561 end562 def test_expand_path_preserves_unc_path_root563 assert_equal("//", File.expand_path("//"))564 assert_equal("//", File.expand_path("//."))565 assert_equal("//", File.expand_path("//.."))566 end567 def test_expand_path_converts_a_pathname_which_starts_with_a_slash_using_host_share568 assert_match(%r"\A//host/share/foo\z"i, File.expand_path('/foo', "//host/share/bar"))569 end if DRIVE570 def test_expand_path_converts_a_pathname_which_starts_with_a_slash_using_a_current_drive571 assert_match(%r"\A#{DRIVE}/foo\z"i, File.expand_path('/foo'))572 end573 def test_expand_path_returns_tainted_strings_or_not574 assert_equal(true, File.expand_path('foo').tainted?)575 assert_equal(true, File.expand_path('foo'.taint).tainted?)576 assert_equal(true, File.expand_path('/foo'.taint).tainted?)577 assert_equal(true, File.expand_path('foo', 'bar').tainted?)578 assert_equal(true, File.expand_path('foo', '/bar'.taint).tainted?)579 assert_equal(true, File.expand_path('foo'.taint, '/bar').tainted?)580 assert_equal(true, File.expand_path('~').tainted?) if ENV["HOME"]581 if DRIVE582 assert_equal(true, File.expand_path('/foo').tainted?)583 assert_equal(false, File.expand_path('//foo').tainted?)584 assert_equal(true, File.expand_path('C:/foo'.taint).tainted?)585 assert_equal(false, File.expand_path('C:/foo').tainted?)586 assert_equal(true, File.expand_path('foo', '/bar').tainted?)587 assert_equal(true, File.expand_path('foo', 'C:/bar'.taint).tainted?)588 assert_equal(true, File.expand_path('foo'.taint, 'C:/bar').tainted?)589 assert_equal(false, File.expand_path('foo', 'C:/bar').tainted?)590 assert_equal(false, File.expand_path('C:/foo/../bar').tainted?)591 assert_equal(false, File.expand_path('foo', '//bar').tainted?)592 else593 assert_equal(false, File.expand_path('/foo').tainted?)594 assert_equal(false, File.expand_path('foo', '/bar').tainted?)595 end596 end597 def test_expand_path_converts_a_pathname_to_an_absolute_pathname_using_home_as_base598 old_home = ENV["HOME"]599 home = ENV["HOME"] = "#{DRIVE}/UserHome"600 assert_equal(home, File.expand_path("~"))601 assert_equal(home, File.expand_path("~", "C:/FooBar"))602 assert_equal(File.join(home, "a"), File.expand_path("~/a", "C:/FooBar"))603 ensure604 ENV["HOME"] = old_home605 end606 def test_expand_path_converts_a_pathname_to_an_absolute_pathname_using_unc_home607 old_home = ENV["HOME"]608 unc_home = ENV["HOME"] = "//UserHome"609 assert_equal(unc_home, File.expand_path("~"))610 ensure611 ENV["HOME"] = old_home612 end if DRIVE613 def test_expand_path_does_not_modify_a_home_string_argument614 old_home = ENV["HOME"]615 home = ENV["HOME"] = "#{DRIVE}/UserHome"616 str = "~/a"617 assert_equal("#{home}/a", File.expand_path(str))618 assert_equal("~/a", str)619 ensure620 ENV["HOME"] = old_home621 end622 def test_expand_path_raises_argument_error_for_any_supplied_username623 bug = '[ruby-core:39597]'624 assert_raise(ArgumentError, bug) { File.expand_path("~anything") }625 end if DRIVE626 def test_expand_path_for_existent_username627 user = ENV['USER']628 skip "ENV['USER'] is not set" unless user629 assert_equal(ENV['HOME'], File.expand_path("~#{user}"))630 end unless DRIVE631 def test_expand_path_error_for_nonexistent_username632 user = "\u{3086 3046 3066 3044}:\u{307F 3084 304A 3046}"633 assert_raise_with_message(ArgumentError, /#{user}/) {File.expand_path("~#{user}")}634 end unless DRIVE635 def test_expand_path_error_for_non_absolute_home636 old_home = ENV["HOME"]637 ENV["HOME"] = "./UserHome"638 assert_raise_with_message(ArgumentError, /non-absolute home/) {File.expand_path("~")}639 ensure640 ENV["HOME"] = old_home641 end642 def test_expand_path_raises_a_type_error_if_not_passed_a_string_type643 assert_raise(TypeError) { File.expand_path(1) }644 assert_raise(TypeError) { File.expand_path(nil) }645 assert_raise(TypeError) { File.expand_path(true) }646 end647 def test_expand_path_expands_dot_dir648 assert_equal("#{DRIVE}/dir", File.expand_path("#{DRIVE}/./dir"))649 end650 def test_expand_path_does_not_expand_wildcards651 assert_equal("#{DRIVE}/*", File.expand_path("./*", "#{DRIVE}/"))652 assert_equal("#{Dir.pwd}/*", File.expand_path("./*", Dir.pwd))653 assert_equal("#{DRIVE}/?", File.expand_path("./?", "#{DRIVE}/"))654 assert_equal("#{Dir.pwd}/?", File.expand_path("./?", Dir.pwd))655 end if DRIVE656 def test_expand_path_does_not_modify_the_string_argument657 str = "./a/b/../c"658 assert_equal("#{Dir.pwd}/a/c", File.expand_path(str, Dir.pwd))659 assert_equal("./a/b/../c", str)660 end661 def test_expand_path_returns_a_string_when_passed_a_string_subclass662 sub = Class.new(String)663 str = sub.new "./a/b/../c"664 path = File.expand_path(str, Dir.pwd)665 assert_equal("#{Dir.pwd}/a/c", path)666 assert_instance_of(String, path)667 end668 def test_expand_path_accepts_objects_that_have_a_to_path_method669 klass = Class.new { def to_path; "a/b/c"; end }670 obj = klass.new671 assert_equal("#{Dir.pwd}/a/b/c", File.expand_path(obj))672 end673 def test_basename674 assert_equal(File.basename(@file).sub(/\.test$/, ""), File.basename(@file, ".test"))675 assert_equal("", s = File.basename(""))676 assert(!s.frozen?, '[ruby-core:24199]')677 assert_equal("foo", s = File.basename("foo"))678 assert(!s.frozen?, '[ruby-core:24199]')679 assert_equal("foo", File.basename("foo", ".ext"))680 assert_equal("foo", File.basename("foo.ext", ".ext"))681 assert_equal("foo", File.basename("foo.ext", ".*"))682 if /cygwin|mingw|mswin|bccwin/ =~ RUBY_PLATFORM683 basename = File.basename(@file)684 assert_equal(basename, File.basename(@file + " "))685 assert_equal(basename, File.basename(@file + "."))686 assert_equal(basename, File.basename(@file + "::$DATA"))687 basename.chomp!(".test")688 assert_equal(basename, File.basename(@file + " ", ".test"))689 assert_equal(basename, File.basename(@file + ".", ".test"))690 assert_equal(basename, File.basename(@file + "::$DATA", ".test"))691 assert_equal(basename, File.basename(@file + " ", ".*"))692 assert_equal(basename, File.basename(@file + ".", ".*"))693 assert_equal(basename, File.basename(@file + "::$DATA", ".*"))694 end695 if File::ALT_SEPARATOR == '\\'696 a = "foo/\225\\\\"697 [%W"cp437 \225", %W"cp932 \225\\"].each do |cp, expected|698 assert_equal(expected.force_encoding(cp), File.basename(a.dup.force_encoding(cp)), cp)699 end700 end701 assert_incompatible_encoding {|d| File.basename(d)}702 assert_incompatible_encoding {|d| File.basename(d, ".*")}703 assert_raise(Encoding::CompatibilityError) {File.basename("foo.ext", ".*".encode("utf-16le"))}704 s = "foo\x93_a".force_encoding("cp932")705 assert_equal(s, File.basename(s, "_a"))706 s = "\u4032.\u3024"707 assert_equal(s, File.basename(s, ".\x95\\".force_encoding("cp932")))708 end709 def test_dirname710 assert(@file.start_with?(File.dirname(@file)))711 assert_equal(".", File.dirname(""))712 assert_incompatible_encoding {|d| File.dirname(d)}713 if File::ALT_SEPARATOR == '\\'714 a = "\225\\\\foo"715 [%W"cp437 \225", %W"cp932 \225\\"].each do |cp, expected|716 assert_equal(expected.force_encoding(cp), File.dirname(a.dup.force_encoding(cp)), cp)717 end718 end719 end720 def test_extname721 assert_equal(".test", File.extname(@file))722 prefixes = ["", "/", ".", "/.", "bar/.", "/bar/."]723 infixes = ["", " ", "."]724 infixes2 = infixes + [".ext "]725 appendixes = [""]726 if /cygwin|mingw|mswin|bccwin/ =~ RUBY_PLATFORM727 appendixes << " " << "." << "::$DATA" << "::$DATA.bar"728 end729 prefixes.each do |prefix|730 appendixes.each do |appendix|731 infixes.each do |infix|732 path = "#{prefix}foo#{infix}#{appendix}"733 assert_equal("", File.extname(path), "File.extname(#{path.inspect})")734 end735 infixes2.each do |infix|736 path = "#{prefix}foo#{infix}.ext#{appendix}"737 assert_equal(".ext", File.extname(path), "File.extname(#{path.inspect})")738 end739 end740 end741 bug3175 = '[ruby-core:29627]'742 assert_equal(".rb", File.extname("/tmp//bla.rb"), bug3175)743 assert_incompatible_encoding {|d| File.extname(d)}744 end745 def test_split746 d, b = File.split(@file)747 assert_equal(File.dirname(@file), d)748 assert_equal(File.basename(@file), b)749 end750 def test_join751 s = "foo" + File::SEPARATOR + "bar" + File::SEPARATOR + "baz"752 assert_equal(s, File.join("foo", "bar", "baz"))753 assert_equal(s, File.join(["foo", "bar", "baz"]))754 o = Object.new755 def o.to_path; "foo"; end756 assert_equal(s, File.join(o, "bar", "baz"))757 assert_equal(s, File.join("foo" + File::SEPARATOR, "bar", File::SEPARATOR + "baz"))758 end759 def test_join_alt_separator760 if File::ALT_SEPARATOR == '\\'761 a = "\225\\"762 b = "foo"763 [%W"cp437 \225\\foo", %W"cp932 \225\\/foo"].each do |cp, expected|764 assert_equal(expected.force_encoding(cp), File.join(a.dup.force_encoding(cp), b.dup.force_encoding(cp)), cp)765 end766 end767 end768 def test_join_ascii_incompatible769 bug7168 = '[ruby-core:48012]'770 names = %w"a b".map {|s| s.encode(Encoding::UTF_16LE)}771 assert_raise(Encoding::CompatibilityError, bug7168) {File.join(*names)}772 assert_raise(Encoding::CompatibilityError, bug7168) {File.join(names)}773 a = Object.new774 b = names[1]775 names = [a, "b"]776 a.singleton_class.class_eval do777 define_method(:to_path) do778 names[1] = b779 "a"780 end781 end782 assert_raise(Encoding::CompatibilityError, bug7168) {File.join(names)}783 end784 def test_truncate785 assert_equal(0, File.truncate(@file, 1))786 assert_file.exist?(@file)787 assert_equal(1, File.size(@file))788 assert_equal(0, File.truncate(@file, 0))789 assert_file.exist?(@file)790 assert_file.zero?(@file)791 make_file("foo", @file)792 assert_raise(Errno::ENOENT) { File.truncate(@nofile, 0) }793 f = File.new(@file, "w")794 assert_equal(0, f.truncate(2))795 assert_file.exist?(@file)796 assert_equal(2, File.size(@file))797 assert_equal(0, f.truncate(0))798 assert_file.exist?(@file)799 assert_file.zero?(@file)800 f.close801 make_file("foo", @file)802 assert_raise(IOError) { File.open(@file) {|ff| ff.truncate(0)} }803 rescue NotImplementedError804 end805 def test_flock ## xxx806 f = File.new(@file, "r+")807 f.flock(File::LOCK_EX)808 f.flock(File::LOCK_SH)809 f.flock(File::LOCK_UN)810 f.close811 rescue NotImplementedError812 end813 def test_test...

Full Screen

Full Screen

test_tempfile.rb

Source:test_tempfile.rb Github

copy

Full Screen

...54 assert_match(/^foo/, File.basename(t.path))55 end56 def test_default_basename57 t = tempfile58 assert_file.exist?(t.path)59 end60 def test_basename_with_suffix61 t = tempfile(["foo", ".txt"])62 assert_match(/^foo/, File.basename(t.path))63 assert_match(/\.txt$/, File.basename(t.path))64 end65 def test_unlink66 t = tempfile("foo")67 path = t.path68 t.close69 assert_file.exist?(path)70 t.unlink71 assert_file.not_exist?(path)72 assert_nil t.path73 end74 def test_unlink_silently_fails_on_windows75 tempfile = tempfile("foo")76 path = tempfile.path77 begin78 assert_nothing_raised do79 tempfile.unlink80 end81 ensure82 tempfile.close83 File.unlink(path) if File.exist?(path)84 end85 end86 def test_unlink_before_close_works_on_posix_systems87 tempfile = tempfile("foo")88 begin89 path = tempfile.path90 tempfile.unlink91 assert_file.not_exist?(path)92 tempfile.write("hello ")93 tempfile.write("world\n")94 tempfile.rewind95 assert_equal "hello world\n", tempfile.read96 ensure97 tempfile.close98 tempfile.unlink99 end100 end unless /mswin|mingw/ =~ RUBY_PLATFORM101 def test_close_and_close_p102 t = tempfile("foo")103 assert_not_predicate(t, :closed?)104 t.close105 assert_predicate(t, :closed?)106 end107 def test_close_with_unlink_now_true_works108 t = tempfile("foo")109 path = t.path110 t.close(true)111 assert_predicate(t, :closed?)112 assert_nil t.path113 assert_file.not_exist?(path)114 end115 def test_close_with_unlink_now_true_does_not_unlink_if_already_unlinked116 t = tempfile("foo")117 path = t.path118 t.unlink119 File.open(path, "w").close120 begin121 t.close(true)122 assert_file.exist?(path)123 ensure124 File.unlink(path) rescue nil125 end126 end unless /mswin|mingw/ =~ RUBY_PLATFORM127 def test_close_bang_works128 t = tempfile("foo")129 path = t.path130 t.close!131 assert_predicate(t, :closed?)132 assert_nil t.path133 assert_file.not_exist?(path)134 end135 def test_close_bang_does_not_unlink_if_already_unlinked136 t = tempfile("foo")137 path = t.path138 t.unlink139 File.open(path, "w").close140 begin141 t.close!142 assert_file.exist?(path)143 ensure144 File.unlink(path) rescue nil145 end146 end unless /mswin|mingw/ =~ RUBY_PLATFORM147 def test_finalizer_does_not_unlink_if_already_unlinked148 assert_in_out_err('-rtempfile', <<-'EOS') do |(filename,*), (error,*)|149file = Tempfile.new('foo')150path = file.path151puts path152file.close!153File.open(path, "w").close154 EOS155 assert_file.exist?(filename)156 File.unlink(filename)157 assert_nil error158 end159 assert_in_out_err('-rtempfile', <<-'EOS') do |(filename,*), (error,*)|160file = Tempfile.new('foo')161path = file.path162file.unlink163puts path164File.open(path, "w").close165 EOS166 if !filename.empty?167 # POSIX unlink semantics supported, continue with test168 assert_file.exist?(filename)169 File.unlink(filename)170 end171 assert_nil error172 end173 end unless /mswin|mingw/ =~ RUBY_PLATFORM174 def test_close_does_not_make_path_nil175 t = tempfile("foo")176 t.close177 assert_not_nil t.path178 end179 def test_close_flushes_buffer180 t = tempfile("foo")181 t.write("hello")182 t.close183 assert_equal 5, File.size(t.path)184 end185 def test_tempfile_is_unlinked_when_ruby_exits186 assert_in_out_err('-rtempfile', <<-'EOS') do |(filename), (error)|187puts Tempfile.new('foo').path188 EOS189 assert_file.for("tempfile must not be exist after GC.").not_exist?(filename)190 assert_nil(error)191 end192 end193 def test_tempfile_finalizer_does_not_run_if_unlinked194 bug8768 = '[ruby-core:56521] [Bug #8768]'195 args = %w(--disable-gems -rtempfile)196 assert_in_out_err(args, <<-'EOS') do |(filename), (error)|197 tmp = Tempfile.new('foo')198 puts tmp.path199 tmp.close200 tmp.unlink201 $DEBUG = true202 EOS203 assert_file.not_exist?(filename)204 assert_nil(error, "#{bug8768} we used to get a confusing 'removing ...done' here")205 end206 end207 def test_size_flushes_buffer_before_determining_file_size208 t = tempfile("foo")209 t.write("hello")210 assert_equal 0, File.size(t.path)211 assert_equal 5, t.size212 assert_equal 5, File.size(t.path)213 end214 def test_size_works_if_file_is_closed215 t = tempfile("foo")216 t.write("hello")217 t.close218 assert_equal 5, t.size219 end220 def test_size_on_empty_file221 t = tempfile("foo")222 t.write("")223 t.close224 assert_equal 0, t.size225 end226 def test_concurrency227 threads = []228 tempfiles = []229 lock = Thread::Mutex.new230 cond = Thread::ConditionVariable.new231 start = false232 4.times do233 threads << Thread.new do234 lock.synchronize do235 while !start236 cond.wait(lock)237 end238 end239 result = []240 30.times do241 result << Tempfile.new('foo')242 end243 Thread.current[:result] = result244 end245 end246 lock.synchronize do247 start = true248 cond.broadcast249 end250 threads.each do |thread|251 thread.join252 tempfiles |= thread[:result]253 end254 filenames = tempfiles.map { |f| f.path }255 begin256 assert_equal filenames.size, filenames.uniq.size257 ensure258 tempfiles.each do |tempfile|259 tempfile.close!260 end261 end262 end263 module M264 end265 def test_extend266 o = tempfile("foo")267 o.extend M268 assert(M === o, "[ruby-dev:32932]")269 end270 def test_tempfile_encoding_nooption271 default_external=Encoding.default_external272 t = tempfile("TEST")273 t.write("\xE6\x9D\xBE\xE6\xB1\x9F")274 t.rewind275 assert_equal(default_external,t.read.encoding)276 end277 def test_tempfile_encoding_ascii8bit278 t = tempfile("TEST",:encoding=>"ascii-8bit")279 t.write("\xE6\x9D\xBE\xE6\xB1\x9F")280 t.rewind281 assert_equal(Encoding::ASCII_8BIT,t.read.encoding)282 end283 def test_tempfile_encoding_ascii8bit2284 t = tempfile("TEST",Dir::tmpdir,:encoding=>"ascii-8bit")285 t.write("\xE6\x9D\xBE\xE6\xB1\x9F")286 t.rewind287 assert_equal(Encoding::ASCII_8BIT,t.read.encoding)288 end289 def test_binmode290 t = tempfile("TEST", mode: IO::BINARY)291 if IO::BINARY.nonzero?292 assert(t.binmode?)293 t.open294 assert(t.binmode?, 'binmode after reopen')295 else296 assert_equal(0600, t.stat.mode & 0777)297 end298 end299 def test_create_with_block300 path = nil301 Tempfile.create("tempfile-create") {|f|302 path = f.path303 assert_file.exist?(path)304 }305 assert_file.not_exist?(path)306 end307 def test_create_without_block308 path = nil309 f = Tempfile.create("tempfile-create")310 path = f.path311 assert_file.exist?(path)312 f.close313 assert_file.exist?(path)314 ensure315 f.close if f && !f.closed?316 File.unlink path if path317 end318 def test_create_default_basename319 path = nil320 Tempfile.create {|f|321 path = f.path322 assert_file.exist?(path)323 }324 assert_file.not_exist?(path)325 end326end...

Full Screen

Full Screen

assert_file

Using AI Code Generation

copy

Full Screen

1assert_file("1.rb")2assert_file("2.rb")3assert_file("3.rb")4assert_file("4.rb")5assert_file("5.rb")6assert_file("6.rb")7assert_file("7.rb")8assert_file("8.rb")9assert_file("9.rb")10assert_file("10.rb")11assert_file("11.rb")12assert_file("12.rb")13assert_file("13.rb")14assert_file("14.rb")15assert_file("15.rb")16assert_file("16.rb")

Full Screen

Full Screen

assert_file

Using AI Code Generation

copy

Full Screen

1Platform.new.assert_file("1.rb")2Platform.new.assert_file("2.rb")3Platform.new.assert_file("3.rb")4Platform.new.assert_file("4.rb")5Platform.new.assert_file("5.rb")6Platform.new.assert_file("6.rb")7Platform.new.assert_file("7.rb")8Platform.new.assert_file("8.rb")9Platform.new.assert_file("9.rb")10Platform.new.assert_file("10.rb")11Platform.new.assert_file("11.rb")12Platform.new.assert_file("12.rb")

Full Screen

Full Screen

assert_file

Using AI Code Generation

copy

Full Screen

1assert_file("1.rb")2assert_file("2.rb")3assert_file("3.rb")4assert_file("4.rb")5assert_file("5.rb")6assert_file("6.rb")7assert_file("7.rb")8assert_file("8.rb")9assert_file("9.rb")10assert_file("10.rb")11assert_file("11.rb")12assert_file("12.rb")

Full Screen

Full Screen

assert_file

Using AI Code Generation

copy

Full Screen

1 @platform.assert_file('1.rb')2 def assert_file(file)3 if File.exists?(file)

Full Screen

Full Screen

assert_file

Using AI Code Generation

copy

Full Screen

1assert_file("1.rb", "File 1.rb does not exist")2assert_not_file("2.rb", "File 2.rb exists")3assert_file_size("1.rb", 0, "File 1.rb has unexpected size")4assert_not_file_size("1.rb", 1, "File 1.rb has unexpected size")5assert_file_content("1.rb", "require 'platform'", "File 1.rb has unexpected content")6assert_not_file_content("1.rb", "require 'platform2'", "File 1.rb has unexpected content")7assert_file_content("1.rb", "require 'platform'", "File 1.rb has unexpected content")

Full Screen

Full Screen

assert_file

Using AI Code Generation

copy

Full Screen

1assert_file("1.rb")2assert_file("2.rb")3assert_file("3.rb")4assert_file("4.rb")5assert_file("5.rb")6assert_file("6.rb")7assert_file("7.rb")8assert_file("8.rb")9assert_file("9.rb")10assert_file("10.rb")11assert_file("11.rb")12assert_file("12.rb")

Full Screen

Full Screen

assert_file

Using AI Code Generation

copy

Full Screen

1assert_file("1.rb", "File 1.rb does not exist")2assert_not_file("2.rb", "File 2.rb exists")3assert_file_size("1.rb", 0, "File 1.rb has unexpected size")4assert_not_file_size("1.rb", 1, "File 1.rb has unexpected size")5assert_file_content("1.rb", "require 'platform'", "File 1.rb has unexpected content")6assert_not_file_content("1.rb", "require 'platform2'", "File 1.rb has unexpected content")7assert_file_content("1.rb", "require 'platform'", "File 1.rb has unexpected content")

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful