Module FakeFS
In: lib/fakefs/fileutils.rb
lib/fakefs/base.rb
lib/fakefs/pathname.rb
lib/fakefs/version.rb
lib/fakefs/kernel.rb
lib/fakefs/globber.rb
lib/fakefs/dir.rb
lib/fakefs/file.rb
lib/fakefs/spec_helpers.rb
lib/fakefs/fake/symlink.rb
lib/fakefs/fake/dir.rb
lib/fakefs/fake/file.rb
lib/fakefs/file_system.rb
lib/fakefs/file_test.rb

FakeFS module

Methods

Classes and Modules

Module FakeFS::FileSystem
Module FakeFS::FileTest
Module FakeFS::FileUtils
Module FakeFS::Globber
Module FakeFS::Kernel
Module FakeFS::SpecHelpers
Module FakeFS::Version
Class FakeFS::Dir
Class FakeFS::FakeDir
Class FakeFS::FakeFile
Class FakeFS::FakeSymlink
Class FakeFS::File
Class FakeFS::Pathname

Constants

SEPARATOR_LIST = "#{Regexp.quote File::ALT_SEPARATOR}" \ "#{Regexp.quote File::SEPARATOR}".freeze
SEPARATOR_PAT = /[#{SEPARATOR_LIST}]/
SEPARATOR_LIST = "#{Regexp.quote File::SEPARATOR}".freeze
SEPARATOR_PAT = /#{Regexp.quote File::SEPARATOR}/

Public Class methods

unconditionally activate

unconditionally clear the fake filesystem

unconditionally deactivate

Create a Pathname object from the given String (or String-like object). If path contains a NUL character (\0), an ArgumentError is raised.

present the fake filesystem to the block

present a fresh new fake filesystem to the block

present a non-fake filesystem to the block

Public Instance methods

Pathname#+ appends a pathname fragment to this one to produce a new Pathname object.

  p1 = Pathname.new("/usr")      # Pathname:/usr
  p2 = p1 + "bin/ruby"           # Pathname:/usr/bin/ruby
  p3 = p1 + "/etc/passwd"        # Pathname:/etc/passwd

This method doesn‘t access the file system; it is pure string manipulation.

Provides for comparing pathnames, case-sensitively.

Compare this pathname with other. The comparison is string-based. Be aware that two different paths (foo.txt and ./foo.txt) can refer to the same file.

Predicate method for testing whether a path is absolute. It returns true if the pathname begins with a slash.

Iterates over and yields a new Pathname object for each element in the given path in ascending order.

 Pathname.new('/path/to/some/file.rb').ascend { |v| p v}
    #<Pathname:/path/to/some/file.rb>
    #<Pathname:/path/to/some>
    #<Pathname:/path/to>
    #<Pathname:/path>
    #<Pathname:/>

 Pathname.new('path/to/some/file.rb').ascend { |v| p v}
    #<Pathname:path/to/some/file.rb>
    #<Pathname:path/to/some>
    #<Pathname:path/to>
    #<Pathname:path>

It doesn‘t access actual filesystem.

This method is available since 1.8.5.

Returns the children of the directory (files and subdirectories, not recursive) as an array of Pathname objects. By default, the returned pathnames will have enough information to access the files. If you set with_directory to false, then the returned pathnames will contain the filename only.

For example:

  pn = Pathname("/usr/lib/ruby/1.8")
  pn.children
    # -> [ Pathname:/usr/lib/ruby/1.8/English.rb,
           Pathname:/usr/lib/ruby/1.8/Env.rb,
           Pathname:/usr/lib/ruby/1.8/abbrev.rb, ... ]
  pn.children(false)
    # -> [ Pathname:English.rb,
           Pathname:Env.rb,
           Pathname:abbrev.rb, ... ]

Note that the result never contain the entries . and .. in the directory because they are not children.

This method has existed since 1.8.1.

chop_basename(path) -> [pre-basename, basename] or nil

Returns clean pathname of self with consecutive slashes and useless dots removed. The filesystem is not accessed.

If consider_symlink is true, then a more conservative algorithm is used to avoid breaking symbolic linkages. This may retain more .. entries than absolutely necessary, but without accessing the filesystem, this can‘t be avoided. See realpath.

Clean the path simply by resolving and removing excess "." and ".." entries. Nothing more, nothing less.

Iterates over and yields a new Pathname object for each element in the given path in descending order.

 Pathname.new('/path/to/some/file.rb').descend { |v| p v}
    #<Pathname:/>
    #<Pathname:/path>
    #<Pathname:/path/to>
    #<Pathname:/path/to/some>
    #<Pathname:/path/to/some/file.rb>

 Pathname.new('path/to/some/file.rb').descend { |v| p v}
    #<Pathname:path>
    #<Pathname:path/to>
    #<Pathname:path/to/some>
    #<Pathname:path/to/some/file.rb>

It doesn‘t access actual filesystem.

This method is available since 1.8.5.

Iterates over the children of the directory (files and subdirectories, not recursive). It yields Pathname object for each child. By default, the yielded pathnames will have enough information to access the files. If you set with_directory to false, then the returned pathnames will contain the filename only.

  Pathname("/usr/local").each_child { |f| p f }
  #=> #<Pathname:/usr/local/share>
  #   #<Pathname:/usr/local/bin>
  #   #<Pathname:/usr/local/games>
  #   #<Pathname:/usr/local/lib>
  #   #<Pathname:/usr/local/include>
  #   #<Pathname:/usr/local/sbin>
  #   #<Pathname:/usr/local/src>
  #   #<Pathname:/usr/local/man>

  Pathname("/usr/local").each_child(false) { |f| p f }
  #=> #<Pathname:share>
  #   #<Pathname:bin>
  #   #<Pathname:games>
  #   #<Pathname:lib>
  #   #<Pathname:include>
  #   #<Pathname:sbin>
  #   #<Pathname:src>
  #   #<Pathname:man>

Iterates over each component of the path.

  Pathname.new("/usr/bin/ruby").each_filename { |filename| ... }
    # yields "usr", "bin", and "ruby".

Pathname#join joins pathnames.

path0.join(path1, …, pathN) is the same as path0 + path1 + … + pathN.

mountpoint? returns true if self points to a mountpoint.

parent returns the parent directory.

This is same as self + ’..’.

Returns the real (absolute) pathname of self in the actual filesystem. The real pathname doesn‘t contain symlinks or useless dots.

The last component of the real pathname can be nonexistent.

Returns the real (absolute) pathname of self in the actual filesystem not containing symlinks or useless dots.

All components of the pathname must exist when this method is called.

The opposite of absolute?

relative_path_from returns a relative path from the argument to the receiver. If self is absolute, the argument must be absolute too. If self is relative, the argument must be relative too.

relative_path_from doesn‘t access the filesystem. It assumes no symlinks.

ArgumentError is raised when it cannot find a relative path.

This method has existed since 1.8.1.

root? is a predicate for root directories. I.e. it returns true if the pathname consists of consecutive slashes.

It doesn‘t access actual filesystem. So it may return false for some pathnames which points to roots such as /usr/...

split_names(path) -> prefix, [name, …]

Return a pathname which is substituted by String#sub.

Return a pathname which the extension of the basename is substituted by repl.

If self has no extension part, repl is appended.

Return the path as a String.

[Validate]