Skip to content

Commit 0cdb19d

Browse files
matchers: docs console output improvements (#1564)
1 parent a40539a commit 0cdb19d

9 files changed

Lines changed: 163 additions & 93 deletions

File tree

webtau-core/src/test/java/org/testingisdocumenting/webtau/MatchersTest.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void removeStepReporter() {
4444

4545
@Test
4646
public void stringComparisonExample() {
47-
doc.console.capture("string-string-comparison", () -> {
47+
doc.console.capture("string-string-comparison-output", () -> {
4848
// string-string-example
4949
String errorMessage = generateErrorMessage();
5050
actual(errorMessage).should(equal("insufficient disk space")); // string and string equality comparison
@@ -54,7 +54,7 @@ public void stringComparisonExample() {
5454

5555
@Test
5656
public void stringNegativeComparisonExample() {
57-
doc.console.capture("string-string-negative-comparison", () -> {
57+
doc.console.capture("string-string-negative-comparison-output", () -> {
5858
// string-string-negative-example
5959
String errorMessage = generateErrorMessage();
6060
actual(errorMessage).shouldNot(equal("completed"));
@@ -64,7 +64,7 @@ public void stringNegativeComparisonExample() {
6464

6565
@Test
6666
public void stringWaitExample() {
67-
doc.console.capture("wait-message", () -> {
67+
doc.console.capture("wait-message-output", () -> {
6868
// wait-consume-message
6969
actual(liveValue(this::consumeMessage)).waitTo(equal("message we wait for"));
7070
// wait-consume-message
@@ -73,7 +73,7 @@ public void stringWaitExample() {
7373

7474
@Test
7575
public void stringWaitNegativeExample() {
76-
doc.console.capture("wait-negative-message", () -> {
76+
doc.console.capture("wait-negative-message-output", () -> {
7777
// wait-negative-consume-message
7878
actual(liveValue(this::consumeMessage)).waitToNot(equal("duplicate"));
7979
// wait-negative-consume-message
@@ -82,9 +82,11 @@ public void stringWaitNegativeExample() {
8282

8383
@Test
8484
public void numberWaitExample() {
85-
// wait-number-records
86-
actual(liveValue(this::countRecords)).waitToBe(greaterThanOrEqual(5));
87-
// wait-number-records
85+
doc.console.capture("wait-tobe-output", () -> {
86+
// wait-number-records
87+
actual(liveValue(this::countRecords)).waitToBe(greaterThanOrEqual(5));
88+
// wait-number-records
89+
});
8890
}
8991

9092
private String consumeMessage() {
@@ -98,7 +100,7 @@ private int countRecords() {
98100

99101
@Test
100102
public void numberComparisonExample() {
101-
doc.console.capture("number-number-comparison", () -> {
103+
doc.console.capture("number-number-comparison-output", () -> {
102104
// number-number-example
103105
double price = calculatePrice();
104106
actual(price, "price").shouldBe(greaterThan(10)); // explict name to use in reporting
@@ -108,10 +110,12 @@ public void numberComparisonExample() {
108110

109111
@Test
110112
public void numberAndStringExample() {
111-
// string-number-example
112-
String numberAsText = "200";
113-
actual(numberAsText).shouldBe(greaterThan(150)); // text and number relative comparison
114-
// string-number-example
113+
doc.console.capture("string-number-comparison-output", () -> {
114+
// string-number-example
115+
String numberAsText = "200";
116+
actual(numberAsText).shouldBe(greaterThan(150)); // text and number relative comparison
117+
// string-number-example
118+
});
115119
}
116120

117121
@Test

webtau-docs/znai/matchers/any-value.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@ provide a value but your focus is on different data.
66
```tabs
77
Groovy:
88
:include-file: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
9-
surroundedBy: "any-value-table-example"
9+
surroundedBy: "any-value-table-example",
10+
noGap: true,
11+
noGapSeparator: true
1012
}
13+
:include-cli-output: doc-artifacts/any-value-table-output.txt
14+
1115
:include-markdown: import-ref.md
1216
1317
Java:
1418
:include-file: org/testingisdocumenting/webtau/MatchersTest.java {
15-
surroundedBy: "any-value-table-example"
19+
surroundedBy: "any-value-table-example",
20+
noGap: true,
21+
noGapSeparator: true
1622
}
23+
:include-cli-output: doc-artifacts/any-value-table-output.txt
24+
1725
:include-markdown: import-ref.md
1826
```
19-
20-
:include-cli-output: doc-artifacts/any-value-table-output.txt {
21-
title: "console output"
22-
}
Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
WebTau provides two ways to assert values: `should` and `waitTo`. They work for business logic testing, HTTP, Browser, and other layers.
22
Methods accept a matcher as a second parameter:
33

4+
```attention-note
45
WebTau provides console output for all the matching it does, regardless of whether it fails or passes.
6+
```
57

68
# Should
79

@@ -13,8 +15,12 @@ Groovy:
1315
:include-file: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
1416
title: "should example",
1517
surroundedBy: "string-string-example",
16-
commentsType: "remove"
18+
commentsType: "remove",
19+
noGap: true,
20+
noGapSeparator: true
1721
}
22+
:include-cli-output: doc-artifacts/string-string-comparison-output.txt
23+
1824
Note: Groovy has a shortcut for `equal` matcher.
1925
2026
:include-markdown: import-ref.md
@@ -23,12 +29,15 @@ Java:
2329
:include-file: org/testingisdocumenting/webtau/MatchersTest.java {
2430
title: "should example",
2531
surroundedBy: "string-string-example",
26-
commentsType: "remove"
32+
commentsType: "remove",
33+
noGap: true,
34+
noGapSeparator: true
2735
}
36+
:include-cli-output: doc-artifacts/string-string-comparison-output.txt
37+
2838
:include-markdown: import-ref.md
2939
```
3040

31-
:include-cli-output: doc-artifacts/string-string-comparison.txt {title: "should console output"}
3241

3342
Use `shouldBe` alias to make a better flow with matchers like `greaterThan`:
3443

@@ -37,15 +46,21 @@ Groovy:
3746
:include-file: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
3847
title: "shouldBe example",
3948
surroundedBy: "string-number-example",
40-
commentsType: "remove"
49+
commentsType: "remove",
50+
noGap: true,
51+
noGapSeparator: true
4152
}
53+
:include-cli-output: doc-artifacts/string-number-comparison-output.txt
4254
4355
Java:
4456
:include-file: org/testingisdocumenting/webtau/MatchersTest.java {
4557
title: "shouldBe example",
4658
surroundedBy: "string-number-example",
47-
commentsType: "remove"
59+
commentsType: "remove",
60+
noGap: true,
61+
noGapSeparator: true
4862
}
63+
:include-cli-output: doc-artifacts/string-number-comparison-output.txt
4964
```
5065

5166
# WaitTo
@@ -56,32 +71,43 @@ Use `waitTo` to wait for a value to eventually match a matcher.
5671
Groovy:
5772
:include-file: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
5873
title: "waitTo example",
59-
surroundedBy: "wait-consume-message"
74+
surroundedBy: "wait-consume-message",
75+
noGap: true,
76+
noGapSeparator: true
6077
}
78+
:include-cli-output: doc-artifacts/wait-message-output.txt
6179
6280
Java:
6381
:include-file: org/testingisdocumenting/webtau/MatchersTest.java {
6482
title: "waitTo example",
65-
surroundedBy: "wait-consume-message"
83+
surroundedBy: "wait-consume-message",
84+
noGap: true,
85+
noGapSeparator: true
6686
}
87+
:include-cli-output: doc-artifacts/wait-message-output.txt
6788
```
6889

69-
:include-cli-output: doc-artifacts/wait-message.txt {title: "wait console output"}
7090

7191
Use `waitToBe` alias to make a better flow with matchers like `greaterThan`:
7292

7393
```tabs
7494
Groovy:
7595
:include-file: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
7696
title: "waitToBe example",
77-
surroundedBy: "wait-number-records"
97+
surroundedBy: "wait-number-records",
98+
noGap: true,
99+
noGapSeparator: true
78100
}
101+
:include-cli-output: doc-artifacts/wait-tobe-output.txt
79102
80103
Java:
81104
:include-file: org/testingisdocumenting/webtau/MatchersTest.java {
82105
title: "waitToBe example",
83-
surroundedBy: "wait-number-records"
106+
surroundedBy: "wait-number-records",
107+
noGap: true,
108+
noGapSeparator: true
84109
}
110+
:include-cli-output: doc-artifacts/wait-tobe-output.txt
85111
```
86112

87113
# Negative Matching
@@ -93,35 +119,39 @@ Groovy:
93119
:include-file: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
94120
title: "shouldNot example",
95121
surroundedBy: "string-string-negative-example",
96-
noGap: true
122+
noGap: true,
123+
noGapSeparator: true
97124
}
98-
:include-cli-output: doc-artifacts/string-string-negative-comparison.txt
125+
:include-cli-output: doc-artifacts/string-string-negative-comparison-output.txt
99126
100127
Java:
101128
:include-file: org/testingisdocumenting/webtau/MatchersTest.java {
102129
title: "shouldNot example",
103130
surroundedBy: "string-string-negative-example",
104-
noGap: true
131+
noGap: true,
132+
noGapSeparator: true
105133
}
106-
:include-cli-output: doc-artifacts/string-string-negative-comparison.txt
134+
:include-cli-output: doc-artifacts/string-string-negative-comparison-output.txt
107135
```
108136

109137
```tabs
110138
Groovy:
111139
:include-file: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
112140
title: "waitToNot example",
113141
surroundedBy: "wait-negative-consume-message",
114-
noGap: true
142+
noGap: true,
143+
noGapSeparator: true
115144
}
116-
:include-cli-output: doc-artifacts/wait-negative-message.txt
145+
:include-cli-output: doc-artifacts/wait-negative-message-output.txt
117146
118147
Java:
119148
:include-file: org/testingisdocumenting/webtau/MatchersTest.java {
120149
title: "waitToNot example",
121150
surroundedBy: "wait-negative-consume-message",
122-
noGap: true
151+
noGap: true,
152+
noGapSeparator: true
123153
}
124-
:include-cli-output: doc-artifacts/wait-negative-message.txt
154+
:include-cli-output: doc-artifacts/wait-negative-message-output.txt
125155
```
126156

127157
# Failure Output
@@ -135,15 +165,17 @@ Groovy:
135165
:include-file: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
136166
title: "assertion",
137167
surroundedBy: "failed-list",
138-
noGap: true
168+
noGap: true,
169+
noGapSeparator: true
139170
}
140171
:include-cli-output: doc-artifacts/list-failure.txt
141172
142173
Java:
143174
:include-file: org/testingisdocumenting/webtau/MatchersTest.java {
144175
title: "assertion",
145176
surroundedBy: "failed-list",
146-
noGap: true
177+
noGap: true,
178+
noGapSeparator: true
147179
}
148180
:include-cli-output: doc-artifacts/list-failure.txt
149181
```

webtau-docs/znai/matchers/java-beans-and-records.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,22 @@ Use `contain` with `TableData` to partially compare list of java beans.
7979
Groovy:
8080
:include-file: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
8181
surroundedBy: "beans-table-contain-example",
82-
commentsType: "inline"
82+
commentsType: "inline",
83+
noGap: true,
84+
noGapSeparator: true
8385
}
86+
:include-cli-output: doc-artifacts/beans-table-contain-output.txt
8487
8588
Java:
8689
:include-file: org/testingisdocumenting/webtau/MatchersTest.java {
8790
surroundedBy: "beans-table-contain-example",
88-
commentsType: "inline"
91+
commentsType: "inline",
92+
noGap: true,
93+
noGapSeparator: true
8994
}
95+
:include-cli-output: doc-artifacts/beans-table-contain-output.txt
9096
```
9197

92-
:include-cli-output: doc-artifacts/beans-table-contain-output.txt {title: "contain handler output"}
93-
9498
# Java Records
9599

96100
WebTau compares Java Records with maps and tables in the same way as Java Beans.

webtau-docs/znai/matchers/maps.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@ When two maps are not equal, WebTau generates all the required info to investiga
55
```tabs
66
Groovy:
77
:include-file: org/testingisdocumenting/webtau/expectation/equality/handlers/MapMatchersGroovyExamplesTest.groovy {
8-
surroundedBy: "maps-equal-mismatch"
8+
surroundedBy: "maps-equal-mismatch",
9+
noGap: true,
10+
noGapSeparator: true
911
}
12+
:include-cli-output: doc-artifacts/maps-equal-console-output.txt
1013
:include-markdown: import-ref.md
1114
1215
Java:
1316
:include-file: org/testingisdocumenting/webtau/expectation/equality/handlers/MapMatchersJavaExamplesTest.java {
14-
surroundedBy: "maps-equal-mismatch"
17+
surroundedBy: "maps-equal-mismatch",
18+
noGap: true,
19+
noGapSeparator: true
1520
}
21+
:include-cli-output: doc-artifacts/maps-equal-console-output.txt
1622
:include-markdown: import-ref.md
1723
```
1824

19-
:include-cli-output: doc-artifacts/maps-equal-console-output.txt {
20-
title: "console output"
21-
}
2225

2326
# Contain
2427

@@ -27,14 +30,18 @@ Use `contain` matcher to check if one map is a subset of another:
2730
```tabs
2831
Groovy:
2932
:include-file: org/testingisdocumenting/webtau/expectation/equality/handlers/MapMatchersGroovyExamplesTest.groovy {
30-
surroundedBy: "maps-contain-mismatch"
33+
surroundedBy: "maps-contain-mismatch",
34+
noGap: true,
35+
noGapSeparator: true
3136
}
37+
:include-cli-output: doc-artifacts/maps-contain-console-output.txt
38+
3239
Java:
3340
:include-file: org/testingisdocumenting/webtau/expectation/equality/handlers/MapMatchersJavaExamplesTest.java {
34-
surroundedBy: "maps-contain-mismatch"
41+
surroundedBy: "maps-contain-mismatch",
42+
noGap: true,
43+
noGapSeparator: true
3544
}
45+
:include-cli-output: doc-artifacts/maps-contain-console-output.txt
3646
```
3747

38-
:include-cli-output: doc-artifacts/maps-contain-console-output.txt {
39-
title: "console output"
40-
}

0 commit comments

Comments
 (0)