Skip to content

Commit 99aeb98

Browse files
committed
d updated markdown snippets
1 parent ef64508 commit 99aeb98

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

approvaltests/docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
* [Features](#features)
99
* [How Tos](#how-tos)
10+
* [Reference](#reference)
1011
* [Configuration](#configuration)
1112
* [Main concepts for ApprovalTests](#main-concepts-for-approvaltests)<!-- endToc -->
1213

approvaltests/docs/reference/Naming.md

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
<!-- toc -->
66
## Contents
77

8-
* [Paintables](#paintables)
9-
* [Why](#why)
10-
* [How To](#how-to)
11-
* [create an animated gif](#create-an-animated-gif)<!-- endToc -->
8+
* [Additional Naming Parameters](#additional-naming-parameters)
9+
* [How to do this](#how-to-do-this)
10+
* [The old way](#the-old-way)
11+
* [The new way](#the-new-way)
12+
* [Adding to an existing scenario](#adding-to-an-existing-scenario)
13+
* [Parameterized Tests](#parameterized-tests)
14+
* [Only running on a specific machine](#only-running-on-a-specific-machine)
15+
* [Capturing approvals from CI](#capturing-approvals-from-ci)<!-- endToc -->
1216

1317
## Additional Naming Parameters
1418

@@ -28,23 +32,47 @@ The way this is handled is through the naming factories. This will give you appr
2832
### The old way
2933
There is a global namer factory that can be accessed with a try/catch. While this way works, it is not thread-safe
3034
and can cause trouble when running tests in parallel. Here is an example of how to do it:
31-
snippet: namer_factory_example
35+
<!-- snippet: namer_factory_example -->
36+
<a id='snippet-namer_factory_example'></a>
37+
```java
38+
try (NamedEnvironment namer = NamerFactory.withParameters("title", "chapter"))
39+
{
40+
Approvals.verify("data");
41+
}
42+
```
43+
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/namer/NamerFactoryForOptionsTest.java#L27-L32' title='Snippet source file'>snippet source</a> | <a href='#snippet-namer_factory_example' title='Start of snippet'>anchor</a></sup>
44+
<!-- endSnippet -->
3245

3346
This will result in a file named:
3447
`ClassName.methodName.firstString.secondString.approved.txt`
3548

3649
### The new way
3750
With the addition of `Options` you can now set additional naming information in a thread-safe way. Here is an example of how to do that:
3851

39-
snippet: additional_information_example
52+
<!-- snippet: additional_information_example -->
53+
<a id='snippet-additional_information_example'></a>
54+
```java
55+
Approvals.verify("data", Approvals.NAMES.withParameters("title", "chapter"));
56+
```
57+
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/namer/NamerFactoryForOptionsTest.java#L37-L39' title='Snippet source file'>snippet source</a> | <a href='#snippet-additional_information_example' title='Start of snippet'>anchor</a></sup>
58+
<!-- endSnippet -->
4059

4160
This will result in a file named:
4261
`ClassName.methodName.firstString.secondString.approved.txt`
4362

4463
#### Adding to an existing scenario
4564
If there is already an `Options` created, you can add to it using the `.and` keyword. Here is an example:
4665

47-
snippet: options_and
66+
<!-- snippet: options_and -->
67+
<a id='snippet-options_and'></a>
68+
```java
69+
Options options = Approvals.NAMES.asOsSpecificTest().and(Approvals.NAMES::asMachineNameSpecificTest);
70+
ApprovalNamer namer = options.forFile().getNamer();
71+
String name = namer.getApprovedFile(".txt").getName();
72+
assertEquals("NamerFactoryForOptionsTest.testMachineSpecificTest.Mac_OS_X.lars-mbp-14.approved.txt", name);
73+
```
74+
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/namer/NamerFactoryForOptionsTest.java#L46-L51' title='Snippet source file'>snippet source</a> | <a href='#snippet-options_and' title='Start of snippet'>anchor</a></sup>
75+
<!-- endSnippet -->
4876

4977
This will result in a file named:
5078
`ClassName.methodName.OSName.machineName.approved.txt`

0 commit comments

Comments
 (0)