ReplayFileSystem class

A file system that replays invocations from a prior recording for use in tests.

This will replay all invocations (methods, property getters, and property setters) that occur on it, based on an opaque recording that was generated in RecordingFileSystem. All activity in the File, Directory, Link, IOSink, and RandomAccessFile instances returned from this API will also be replayed from the same recording.

Once an invocation has been replayed once, it is marked as such and will not be eligible for further replay. If an eligible invocation cannot be found that matches an incoming invocation, a NoMatchingInvocationError will be thrown.

This class is intended for use in tests, where you would otherwise have to set up complex mocks or fake file systems. With this class, the process is as follows:

  • You record the file system activity during a real run of your program by injecting a RecordingFileSystem that delegates to your real file system.
  • You serialize that recording to disk as your program finishes.
  • You use that recording in tests to create a mock file system that knows how to respond to the exact invocations your program makes. Any invocations that aren't in the recording will throw, and you can make assertions in your tests about which methods were invoked and in what order.

Implementation note: this class uses noSuchMethod to dynamically handle invocations. As a result, method references on objects herein will not pass is checks or checked-mode checks on type. For example:

typedef FileStat StatSync(String path);
FileSystem fs = new ReplayFileSystem(directory);

StatSync method = fs.statSync;     // Will fail in checked-mode
fs.statSync is StatSync            // Will return false
fs.statSync is Function            // Will return false

dynamic method2 = fs.statSync;     // OK
FileStat stat = method2('/path');  // OK

See also:

Inheritance

Constructors

ReplayFileSystem({@required Directory recording })
Creates a new ReplayFileSystem. [...]
factory

Properties

currentDirectory Directory
Creates a directory object pointing to the current working directory.
read / write, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
isWatchSupported bool
Tests if FileSystemEntity.watch is supported on the current system.
read-only, inherited
path Context
An object for manipulating paths in this file system.
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
systemTempDirectory Directory
Gets the system temp directory. [...]
read-only, inherited

Methods

directory(dynamic path) Directory
Returns a reference to a Directory at path. [...]
inherited
file(dynamic path) File
Returns a reference to a File at path. [...]
inherited
getPath(dynamic path) String
Gets the string path represented by the specified generic path. [...]
@protected, inherited
identical(String path1, String path2) Future<bool>
Checks whether two paths refer to the same object in the file system. Returns a Future<bool> that completes with the result. [...]
inherited
identicalSync(String path1, String path2) bool
Synchronously checks whether two paths refer to the same object in the file system. [...]
inherited
isDirectory(String path) Future<bool>
Checks if type(path) returns io.FileSystemEntityType.DIRECTORY.
inherited
isDirectorySync(String path) bool
Synchronously checks if type(path) returns io.FileSystemEntityType.DIRECTORY.
inherited
isFile(String path) Future<bool>
Checks if type(path) returns io.FileSystemEntityType.FILE.
inherited
isFileSync(String path) bool
Synchronously checks if type(path) returns io.FileSystemEntityType.FILE.
inherited
Checks if type(path) returns io.FileSystemEntityType.LINK.
inherited
isLinkSync(String path) bool
Synchronously checks if type(path) returns io.FileSystemEntityType.LINK.
inherited
Returns a reference to a Link at path. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
stat(String path) Future<FileStat>
Asynchronously calls the operating system's stat() function on path. Returns a Future which completes with a FileStat object containing the data returned by stat(). If the call fails, completes the future with a FileStat object with .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid.
inherited
statSync(String path) FileStat
Calls the operating system's stat() function on path. Returns a FileStat object containing the data returned by stat(). If the call fails, returns a FileStat object with .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid.
inherited
toString() String
Returns a string representation of this object.
inherited
type(String path, { bool followLinks: true }) Future<FileSystemEntityType>
Finds the type of file system object that a path points to. Returns a Future that completes with the result. [...]
inherited
typeSync(String path, { bool followLinks: true }) FileSystemEntityType
Syncronously finds the type of file system object that a path points to. Returns a FileSystemEntityType. [...]
inherited

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited