Skip to content

Latest commit

 

History

History
142 lines (103 loc) · 5.88 KB

Options.md

File metadata and controls

142 lines (103 loc) · 5.88 KB

Options

Contents

Introduction

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.

Fluent Interface

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")

snippet source | anchor

Reporters

Reporters launch diff tools upon failure. There are two ways to set a Reporter.

  1. Pass in a Reporter object to the Options constructor, for example:

Approvals::verify("text to be verified", Options(Windows::AraxisMergeReporter()));

snippet source | anchor

  1. Call .withReporter() on an existing Options object, for example:

Approvals::verify("text to be verified",
                  Options().withReporter(Mac::AraxisMergeReporter()));

snippet source | anchor

Scrubbers

Scrubbers clean output to help remove inconsistent pieces of text, such as dates. There are two ways to set a Scrubber.

  1. Pass in a function pointer to the Options constructor, for example:

Approvals::verifyAll("IDs", v, Options(Scrubbers::scrubGuid));

snippet source | anchor

  1. Call .withScrubber() with a function pointer, for example:

Approvals::verifyAll("IDs", v, Options().withScrubber(Scrubbers::scrubGuid));

snippet source | anchor

File Options

The Options::FileOptions class exists to customise the .approved and .received files in various ways.

For now, it just controls the file extension.

File Extensions

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"));

snippet source | anchor

Note: withFileExtension() returns an Options object, so it's possible to keep appending more with...() calls.

Defaults

The default constructor for Options does:

Adding to Existing Options object

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());
}

Back to User Guide