- Introduction
- Fluent Interface
- Reporters
- Scrubbers
- File Options
- Defaults
- Adding to Existing Options object
There are many things you might want to tweak with Approval Tests. Options
is the entry-point for many of the changes.
It is on all verify()
methods, as an optional parameter.
Note: If you are interested in why we moved from "optional Reporter arguments" to "optional Options arguments", see Why We Are Converting To Options.
Options utilizes a fluent interface, allowing you to chain together commands. Each returned object is a new copy.
Options()
.withReporter(QuietReporter())
.withScrubber(Scrubbers::scrubGuid)
.fileOptions().withFileExtension(".json")
Reporters launch diff tools upon failure. There are two ways to set a Reporter.
- Pass in a Reporter object to the Options constructor, for example:
Approvals::verify("text to be verified", Options(Windows::AraxisMergeReporter()));
- Call
.withReporter()
on an existing Options object, for example:
Approvals::verify("text to be verified",
Options().withReporter(Mac::AraxisMergeReporter()));
Scrubbers clean output to help remove inconsistent pieces of text, such as dates. There are two ways to set a Scrubber.
- Pass in a function pointer to the Options constructor, for example:
Approvals::verifyAll("IDs", v, Options(Scrubbers::scrubGuid));
- Call
.withScrubber()
with a function pointer, for example:
Approvals::verifyAll("IDs", v, Options().withScrubber(Scrubbers::scrubGuid));
The Options::FileOptions
class exists to customise the .approved
and .received
files in various ways.
For now, it just controls the file extension.
If you want to change the file extension of both the approved and received files, use withFileExtension()
.
Approvals::verify("text to be verified",
Options().fileOptions().withFileExtension(".xyz"));
Note: withFileExtension()
returns an Options
object, so it's possible to keep appending more with...()
calls.
The default constructor for Options does:
- no scrubbing
- uses file extension
.txt
- uses whatever is currently set as the default reporter.
Because of the fluent options, you can modify a specific option from an existing Options object, while retaining all other settings, and not changing the original object.
verifyWithQuietReporter(std::string text, const Options& o)
{
Approvals::verify(text, o.withReporter(QuietReporter());
}