RecordingFileSystem class

File system that records invocations for later playback in tests.

This will record all invocations (methods, property getters, and property setters) that occur on it, in an opaque format that can later be used in ReplayFileSystem. All activity in the File, Directory, Link, IOSink, and RandomAccessFile instances returned from this API will also be recorded.

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 RecordingFileSystem(delegate: delegate, destination: dir);

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

RecordingFileSystem({@required FileSystem delegate, @required Directory destination, Stopwatch stopwatch })
Creates a new RecordingFileSystem. [...]
factory

Properties

delegate FileSystem
The file system to which invocations will be forwarded upon recording.
read-only
recording LiveRecording
The recording generated by invocations on this file system. [...]
read-only
stopwatch Stopwatch
The stopwatch used to record timestamps on invocation events. [...]
read-only
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