Skip to content

Commit 30b98f0

Browse files
matchers: intro docs refersh (#1555)
1 parent ec0a2c7 commit 30b98f0

File tree

12 files changed

+116
-35
lines changed

12 files changed

+116
-35
lines changed

webtau-core-groovy/src/test/groovy/org/testingisdocumenting/webtau/MatchersGroovyTest.groovy

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,32 @@ class MatchersGroovyTest {
4343
// string-string-example
4444
}
4545

46+
@Test
47+
void "string negative comparison example"() {
48+
// string-string-negative-example
49+
def errorMessage = generateErrorMessage()
50+
errorMessage.shouldNot == "completed"
51+
// string-string-negative-example
52+
}
53+
4654
@Test
4755
void "string wait example"() {
4856
// wait-consume-message
49-
actual(liveValue(this.&consumeMessage)).waitTo == "message we wait for"
57+
actual(liveValue(this::consumeMessage)).waitTo == "message we wait for"
5058
// wait-consume-message
5159
}
5260

61+
@Test
62+
void "string wait negative example"() {
63+
// wait-negative-consume-message
64+
actual(liveValue(this::consumeMessage)).waitToNot == "duplicate"
65+
// wait-negative-consume-message
66+
}
67+
5368
@Test
5469
void "number wait example"() {
5570
// wait-number-records
56-
actual(liveValue(this.&countRecords)).waitToBe >= 5
71+
actual(liveValue(this::countRecords)).waitToBe >= 5
5772
// wait-number-records
5873
}
5974

@@ -179,17 +194,21 @@ class MatchersGroovyTest {
179194

180195
@Test
181196
void "any of matcher example"() {
197+
// any-of-matcher-standalone
182198
def dateAsText = "2018-06-10"
183199
dateAsText.should == anyOf("2018-06-11", LocalDate.of(2018, 6, 10))
200+
// any-of-matcher-standalone
184201
}
185202

186203
@Test
187204
void "any of matcher with other matcher example"() {
205+
// any-of-matcher-combo
188206
def dateAsText = "2018-06-10"
189207
dateAsText.should == anyOf("2018-06-11", greaterThan(LocalDate.of(2018, 1, 1)))
190208

191209
def message = "hello world"
192210
message.shouldNot == anyOf("hello", contain("super"))
211+
// any-of-matcher-combo
193212
}
194213

195214
@Test

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ public void stringComparisonExample() {
5252
});
5353
}
5454

55+
@Test
56+
public void stringNegativeComparisonExample() {
57+
doc.console.capture("string-string-negative-comparison", () -> {
58+
// string-string-negative-example
59+
String errorMessage = generateErrorMessage();
60+
actual(errorMessage).shouldNot(equal("completed"));
61+
// string-string-negative-example
62+
});
63+
}
64+
5565
@Test
5666
public void stringWaitExample() {
5767
doc.console.capture("wait-message", () -> {
@@ -61,6 +71,15 @@ public void stringWaitExample() {
6171
});
6272
}
6373

74+
@Test
75+
public void stringWaitNegativeExample() {
76+
doc.console.capture("wait-negative-message", () -> {
77+
// wait-negative-consume-message
78+
actual(liveValue(this::consumeMessage)).waitToNot(equal("duplicate"));
79+
// wait-negative-consume-message
80+
});
81+
}
82+
6483
@Test
6584
public void numberWaitExample() {
6685
// wait-number-records

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ Use `anyOf` matcher to match an expected value against any of the provided value
55

66
```tabs
77
Groovy:
8-
:include-groovy: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
9-
entry: "any of matcher example",
10-
bodyOnly: true
8+
:include-file: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
9+
surroundedBy: "any-of-matcher-standalone"
1110
}
1211
:include-markdown: import-ref.md
1312
@@ -25,16 +24,13 @@ You can mix values and other matchers passed to `anyOf`
2524

2625
```tabs
2726
Groovy:
28-
:include-groovy: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
29-
entry: "any of matcher with other matcher example",
30-
bodyOnly: true
27+
:include-file: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
28+
surroundedBy: "any-of-matcher-combo"
3129
}
3230
3331
Java:
3432
:include-java: org/testingisdocumenting/webtau/MatchersTest.java {
3533
entry: "anyOfMatcherWithOtherMatcherExample",
3634
bodyOnly: true
3735
}
38-
```
39-
40-
:include-markdown: static-import.md
36+
```

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,4 @@ Java:
1919

2020
:include-cli-output: doc-artifacts/any-value-table-output.txt {
2121
title: "console output"
22-
}
23-
24-
:include-markdown: static-import.md
22+
}

webtau-docs/znai/matchers/contain-exactly.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ Groovy:
99
:include-file: org/testingisdocumenting/webtau/expectation/contain/ContainExactlyMatcherGroovyTest.groovy {
1010
surroundedBy: "possible-mismatches-example"
1111
}
12+
:include-markdown: import-ref.md
1213
Java:
1314
:include-file: org/testingisdocumenting/webtau/expectation/contain/ContainExactlyMatcherJavaTest.java {
1415
surroundedBy: "possible-mismatches-example"
1516
}
17+
:include-markdown: import-ref.md
1618
```
1719

1820
Console output displays potential mismatches to help with investigation:

webtau-docs/znai/matchers/import-and-dependencies.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Matchers Specific Import
44

5-
To specifically import `matchers` only use
5+
To specifically import `matchers` only use:
66

77
```tabs
88
Groovy:
@@ -14,3 +14,16 @@ Java:
1414
:include-file: org/testingisdocumenting/webtau/expectation/equality/handlers/StringMatchersJavaExamplesTest.java {title: "matchers import", include: "Matchers.*"}
1515
:include-file: maven/core-dep.xml {title: "maven dependency"}
1616
```
17+
18+
# Core Module Import
19+
20+
To have one import for `matchers` and utilities like `list`, `map`, `table` use:
21+
22+
```tabs
23+
Groovy:
24+
:include-file: org/testingisdocumenting/webtau/MatchersTest.java { include: "WebTauCore.*", replace: [";", ""] }
25+
26+
Java:
27+
:include-file: org/testingisdocumenting/webtau/MatchersTest.java { include: "WebTauCore.*" }
28+
```
29+

webtau-docs/znai/matchers/introduction.md

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
WebTau provides two methods to assert values: `should` and `waitTo`. They work for business logic testing, HTTP, Browser, and other layers.
1+
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-
WebTau provides console output of all the matches it does, regardless of whether it fails or passes.
4+
WebTau provides console output for all the matching it does, regardless of whether it fails or passes.
55

66
# Should
77

@@ -15,7 +15,6 @@ Groovy:
1515
surroundedBy: "string-string-example",
1616
commentsType: "remove"
1717
}
18-
1918
Note: Groovy has a shortcut for `equal` matcher.
2019
2120
:include-markdown: import-ref.md
@@ -85,6 +84,46 @@ Java:
8584
}
8685
```
8786

87+
# Negative Matching
88+
89+
Both `should` and `waitTo` have negative forms:
90+
91+
```tabs
92+
Groovy:
93+
:include-file: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
94+
title: "shouldNot example",
95+
surroundedBy: "string-string-negative-example",
96+
noGap: true
97+
}
98+
:include-cli-output: doc-artifacts/string-string-negative-comparison.txt
99+
100+
Java:
101+
:include-file: org/testingisdocumenting/webtau/MatchersTest.java {
102+
title: "shouldNot example",
103+
surroundedBy: "string-string-negative-example",
104+
noGap: true
105+
}
106+
:include-cli-output: doc-artifacts/string-string-negative-comparison.txt
107+
```
108+
109+
```tabs
110+
Groovy:
111+
:include-file: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
112+
title: "waitToNot example",
113+
surroundedBy: "wait-negative-consume-message",
114+
noGap: true
115+
}
116+
:include-cli-output: doc-artifacts/wait-negative-message.txt
117+
118+
Java:
119+
:include-file: org/testingisdocumenting/webtau/MatchersTest.java {
120+
title: "waitToNot example",
121+
surroundedBy: "wait-negative-consume-message",
122+
noGap: true
123+
}
124+
:include-cli-output: doc-artifacts/wait-negative-message.txt
125+
```
126+
88127
# Failure Output
89128

90129
Above you saw how WebTau outputs matched information.
@@ -95,16 +134,16 @@ In case of failed assertion WebTau outputs additional information about the actu
95134
Groovy:
96135
:include-file: org/testingisdocumenting/webtau/MatchersGroovyTest.groovy {
97136
title: "assertion",
98-
surroundedBy: "failed-list"
137+
surroundedBy: "failed-list",
138+
noGap: true
99139
}
140+
:include-cli-output: doc-artifacts/list-failure.txt
100141
101142
Java:
102143
:include-file: org/testingisdocumenting/webtau/MatchersTest.java {
103144
title: "assertion",
104-
surroundedBy: "failed-list"
145+
surroundedBy: "failed-list",
146+
noGap: true
105147
}
148+
:include-cli-output: doc-artifacts/list-failure.txt
106149
```
107-
108-
:include-cli-output: doc-artifacts/list-failure.txt {title: "failed assertion console output"}
109-
110-
:include-markdown: static-import.md

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ Java:
9191

9292
:include-cli-output: doc-artifacts/beans-table-contain-output.txt {title: "contain handler output"}
9393

94-
:include-markdown: static-import.md
95-
9694
# Java Records
9795

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

webtau-docs/znai/matchers/static-import.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

webtau-docs/znai/matchers/universal-compare.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,3 @@ Java:
7575
}
7676
```
7777

78-
:include-markdown: static-import.md
79-

0 commit comments

Comments
 (0)