Skip to content

Latest commit

 

History

History
93 lines (59 loc) · 3.4 KB

File metadata and controls

93 lines (59 loc) · 3.4 KB

Namers

Contents

The Purpose of Namers

Approvals::verify(text);

could be written as:

REQUIRE(text == (loadContentsFromFile("FileName.TestName.approved.txt"));

Part of Approval Tests' "Convention over Configuration" is to remove this by automatically creating meaningful file names, and therefore it could be written as:

REQUIRE(text == (loadContentsFromFile(namer.getApprovedFile()));

"If you always have to do something, you should never have to do something."

Since all of your REQUIREs would look like this, we can simplify it with the above Approvals::verify(text); - and this is enabled by the ApprovalNamers.

The Parts of Namers

The conventional layout for files saved with Approvals::verify() and related functions is:

  • path_to_test_file/FileName.TestName.approved.txt
  • path_to_test_file/FileName.TestName.received.txt

The Approval Namer is responsible for creating these two names.

The interface for this is ApprovalNamer.

Registering a Custom Namer

If you ever want to create a custom namer, Approval Tests has a mechanism to change which namer it uses by default. Please note that you need to create a function that creates new namers.

auto default_namer_disposer = Approvals::useAsDefaultNamer([](){return std::make_shared<FakeNamer>();});

snippet source / anchor

Alternative Namers

SeparateApprovedAndReceivedDirectoriesNamer

The pattern used by this class for file names is:

  • ./approved/[test file name].[test name].[extension]
  • ./received/[test file name].[test name].[extension]

This layout enables Beyond Compare 4 (or any other directory comparison tool) to compare the approved/ and received/ directories, and approve one or more files by copying them (without renaming) from received/ to approved/.

The approved/ and received/ directories are created automatically.

To register this as your default namer, use:

auto default_namer_disposer = SeparateApprovedAndReceivedDirectoriesNamer::useAsDefaultNamer();

snippet source / anchor

Approving multiple files from one test

See MultipleOutputFilesPerTest.


Back to User Guide