mirror of
https://github.com/jlengrand/atrium.git
synced 2026-03-10 08:01:19 +00:00
replace isLessThan with toBeLessThan in README
This commit is contained in:
136
README.md
136
README.md
@@ -303,13 +303,17 @@ you only need to write the `expect(...)` part once and can make several single a
|
||||
The expression which determines the subject of the assertion (`4 + 6` in the above example) is evaluated only once.
|
||||
|
||||
In this sense we could have written it also as follows (which is only the same because `4 + 6` does not have side effects).
|
||||
|
||||
<code-single-explained>
|
||||
|
||||
```kotlin
|
||||
expect(4 + 6).isLessThan(5)
|
||||
expect(4 + 6).isGreaterThan(10)
|
||||
```
|
||||
expect(4 + 6).toBeLessThan(5)
|
||||
expect(4 + 6).toBeGreaterThan(10)
|
||||
```
|
||||
</code-single-explained>
|
||||
|
||||
Correspondingly, the first `expect` statement (which does not hold) throws an `AssertionError`.
|
||||
In the above example, `isLessThan(5)` is already wrong and thus `isGreaterThan(10)` was not evaluated at all
|
||||
In the above example, `toBeLessThan(5)` is already wrong and thus `toBeGreaterThan(10)` was not evaluated at all
|
||||
and correspondingly not reported.
|
||||
|
||||
If you want that both assertions are evaluated together, then use the assertion group syntax as follows:
|
||||
@@ -323,7 +327,7 @@ expect(4 + 6) {
|
||||
toBeGreaterThan(10)
|
||||
}
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L29)</sub> ↓ <sub>[Output](#ex-group)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L40)</sub> ↓ <sub>[Output](#ex-group)</sub>
|
||||
<a name="ex-group"></a>
|
||||
```text
|
||||
expected that subject: 10 (kotlin.Int <1234789>)
|
||||
@@ -336,15 +340,19 @@ An assertion group throws an `AssertionError` at the end of its block; hence rep
|
||||
The reporting can be read as `I expected that the subject of the assertion, which is 10, is less than 5 and is greater than 10`
|
||||
|
||||
You can use `and` as filling element between single assertions and assertion group blocks:
|
||||
```kotlin
|
||||
expect(4 + 6).isLessThan(5).and.isGreaterThan(10)
|
||||
|
||||
expect(4 + 6) {
|
||||
// ...
|
||||
<code-and>
|
||||
|
||||
```kotlin
|
||||
expect(5).toBeGreaterThan(2).and.toBeLessThan(10)
|
||||
|
||||
expect(5) {
|
||||
// ...
|
||||
} and { // if the previous block fails, then this one is not evaluated
|
||||
// ...
|
||||
}
|
||||
```
|
||||
</code-and>
|
||||
|
||||
## Expect an Exception
|
||||
<ex-toThrow1>
|
||||
@@ -355,19 +363,19 @@ expect {
|
||||
throw IllegalArgumentException("name is empty")
|
||||
}.toThrow<IllegalStateException>()
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L37)</sub> ↓ <sub>[Output](#ex-toThrow1)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L64)</sub> ↓ <sub>[Output](#ex-toThrow1)</sub>
|
||||
<a name="ex-toThrow1"></a>
|
||||
```text
|
||||
expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$3$1 <1234789>)
|
||||
expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$7$1 <1234789>)
|
||||
◆ ▶ thrown exception when called: java.lang.IllegalArgumentException
|
||||
◾ is instance of type: IllegalStateException (java.lang.IllegalStateException)
|
||||
ℹ Properties of the unexpected IllegalArgumentException
|
||||
» message: "name is empty" <1234789>
|
||||
» stacktrace:
|
||||
⚬ readme.examples.MostExamplesSpec$1$3$1.invoke(MostExamplesSpec.kt:40)
|
||||
⚬ readme.examples.MostExamplesSpec$1$3$1.invoke(MostExamplesSpec.kt:22)
|
||||
⚬ readme.examples.MostExamplesSpec$1$3.invoke(MostExamplesSpec.kt:239)
|
||||
⚬ readme.examples.MostExamplesSpec$1$3.invoke(MostExamplesSpec.kt:22)
|
||||
⚬ readme.examples.MostExamplesSpec$1$7$1.invoke(MostExamplesSpec.kt:67)
|
||||
⚬ readme.examples.MostExamplesSpec$1$7$1.invoke(MostExamplesSpec.kt:22)
|
||||
⚬ readme.examples.MostExamplesSpec$1$7.invoke(MostExamplesSpec.kt:266)
|
||||
⚬ readme.examples.MostExamplesSpec$1$7.invoke(MostExamplesSpec.kt:22)
|
||||
```
|
||||
</ex-toThrow1>
|
||||
|
||||
@@ -391,10 +399,10 @@ expect {
|
||||
throw IllegalArgumentException()
|
||||
}.toThrow<IllegalArgumentException>().message.toStartWith("firstName")
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L44)</sub> ↓ <sub>[Output](#ex-toThrow2)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L71)</sub> ↓ <sub>[Output](#ex-toThrow2)</sub>
|
||||
<a name="ex-toThrow2"></a>
|
||||
```text
|
||||
expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$4$1 <1234789>)
|
||||
expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$8$1 <1234789>)
|
||||
◆ ▶ thrown exception when called: java.lang.IllegalArgumentException
|
||||
◾ ▶ message: null
|
||||
◾ is instance of type: String (kotlin.String) -- Class: java.lang.String
|
||||
@@ -412,10 +420,10 @@ expect {
|
||||
message { toStartWith("firstName") }
|
||||
}
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L50)</sub> ↓ <sub>[Output](#ex-toThrow3)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L77)</sub> ↓ <sub>[Output](#ex-toThrow3)</sub>
|
||||
<a name="ex-toThrow3"></a>
|
||||
```text
|
||||
expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$5$1 <1234789>)
|
||||
expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$9$1 <1234789>)
|
||||
◆ ▶ thrown exception when called: java.lang.IllegalArgumentException
|
||||
◾ ▶ message: null
|
||||
◾ is instance of type: String (kotlin.String) -- Class: java.lang.String
|
||||
@@ -436,22 +444,22 @@ expect {
|
||||
throw IllegalArgumentException("name is empty", RuntimeException("a cause"))
|
||||
}.notToThrow()
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L58)</sub> ↓ <sub>[Output](#ex-notToThrow)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L85)</sub> ↓ <sub>[Output](#ex-notToThrow)</sub>
|
||||
<a name="ex-notToThrow"></a>
|
||||
```text
|
||||
expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$6$1 <1234789>)
|
||||
expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$10$1 <1234789>)
|
||||
◆ ▶ invoke(): ❗❗ threw java.lang.IllegalArgumentException
|
||||
ℹ Properties of the unexpected IllegalArgumentException
|
||||
» message: "name is empty" <1234789>
|
||||
» stacktrace:
|
||||
⚬ readme.examples.MostExamplesSpec$1$6$1.invoke(MostExamplesSpec.kt:61)
|
||||
⚬ readme.examples.MostExamplesSpec$1$6$1.invoke(MostExamplesSpec.kt:22)
|
||||
⚬ readme.examples.MostExamplesSpec$1$6.invoke(MostExamplesSpec.kt:62)
|
||||
⚬ readme.examples.MostExamplesSpec$1$6.invoke(MostExamplesSpec.kt:22)
|
||||
⚬ readme.examples.MostExamplesSpec$1$10$1.invoke(MostExamplesSpec.kt:88)
|
||||
⚬ readme.examples.MostExamplesSpec$1$10$1.invoke(MostExamplesSpec.kt:22)
|
||||
⚬ readme.examples.MostExamplesSpec$1$10.invoke(MostExamplesSpec.kt:89)
|
||||
⚬ readme.examples.MostExamplesSpec$1$10.invoke(MostExamplesSpec.kt:22)
|
||||
» cause: java.lang.RuntimeException
|
||||
» message: "a cause" <1234789>
|
||||
» stacktrace:
|
||||
⚬ readme.examples.MostExamplesSpec$1$6$1.invoke(MostExamplesSpec.kt:61)
|
||||
⚬ readme.examples.MostExamplesSpec$1$10$1.invoke(MostExamplesSpec.kt:88)
|
||||
```
|
||||
</ex-notToThrow>
|
||||
|
||||
@@ -843,7 +851,7 @@ expect(x).toBeAnInstanceOf<SubType1>()
|
||||
.feature { f(it::number) }
|
||||
.toEqual(2)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L65)</sub> ↓ <sub>[Output](#ex-type-assertions-1)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L92)</sub> ↓ <sub>[Output](#ex-type-assertions-1)</sub>
|
||||
<a name="ex-type-assertions-1"></a>
|
||||
```text
|
||||
expected that subject: SubType2(word=hello, flag=true) (readme.examples.SubType2 <1234789>)
|
||||
@@ -865,7 +873,7 @@ expect(x).toBeAnInstanceOf<SubType2> {
|
||||
feature { f(it::flag) }.toEqual(false)
|
||||
}
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L71)</sub> ↓ <sub>[Output](#ex-type-assertions-2)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L98)</sub> ↓ <sub>[Output](#ex-type-assertions-2)</sub>
|
||||
<a name="ex-type-assertions-2"></a>
|
||||
```text
|
||||
expected that subject: SubType2(word=hello, flag=true) (readme.examples.SubType2 <1234789>)
|
||||
@@ -894,7 +902,7 @@ Let us look at the case where the subject of the assertion has a [nullable type]
|
||||
val slogan1: String? = "postulating assertions made easy"
|
||||
expect(slogan1).toEqual(null)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L79)</sub> ↓ <sub>[Output](#ex-nullable-1)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L106)</sub> ↓ <sub>[Output](#ex-nullable-1)</sub>
|
||||
<a name="ex-nullable-1"></a>
|
||||
```text
|
||||
expected that subject: "postulating assertions made easy" <1234789>
|
||||
@@ -908,7 +916,7 @@ expected that subject: "postulating assertions made easy" <1234789>
|
||||
val slogan2: String? = null
|
||||
expect(slogan2).toEqual("postulating assertions made easy")
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L83)</sub> ↓ <sub>[Output](#ex-nullable-2)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L110)</sub> ↓ <sub>[Output](#ex-nullable-2)</sub>
|
||||
<a name="ex-nullable-2"></a>
|
||||
```text
|
||||
expected that subject: null
|
||||
@@ -929,7 +937,7 @@ expect(slogan2) // subject has type String?
|
||||
.notToEqualNull() // subject is narrowed to String
|
||||
.toStartWith("atrium")
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L88)</sub> ↓ <sub>[Output](#ex-nullable-3)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L115)</sub> ↓ <sub>[Output](#ex-nullable-3)</sub>
|
||||
<a name="ex-nullable-3"></a>
|
||||
```text
|
||||
expected that subject: null
|
||||
@@ -946,7 +954,7 @@ one without (example above) and one with `assertionCreator`-lambda (example belo
|
||||
```kotlin
|
||||
expect(slogan2).notToEqualNull { toStartWith("atrium") }
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L93)</sub> ↓ <sub>[Output](#ex-nullable-4)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L120)</sub> ↓ <sub>[Output](#ex-nullable-4)</sub>
|
||||
<a name="ex-nullable-4"></a>
|
||||
```text
|
||||
expected that subject: null
|
||||
@@ -985,7 +993,7 @@ The following sub sections show both use cases by examples.
|
||||
```kotlin
|
||||
expect(listOf(1, 2, 2, 4)).contains(2, 3)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L97)</sub> ↓ <sub>[Output](#ex-collection-short-1)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L124)</sub> ↓ <sub>[Output](#ex-collection-short-1)</sub>
|
||||
<a name="ex-collection-short-1"></a>
|
||||
```text
|
||||
expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>)
|
||||
@@ -1024,7 +1032,7 @@ expect(listOf(1, 2, 2, 4)).contains(
|
||||
{ toBeGreaterThan(2).toBeLessThan(4) }
|
||||
)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L101)</sub> ↓ <sub>[Output](#ex-collection-short-2)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L128)</sub> ↓ <sub>[Output](#ex-collection-short-2)</sub>
|
||||
<a name="ex-collection-short-2"></a>
|
||||
```text
|
||||
expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>)
|
||||
@@ -1048,8 +1056,8 @@ the opposite of `inAnyOrder.atLeast(1)` and is named `containsExactly`.
|
||||
Again, Atrium provides two overloads for it, one for values,
|
||||
e.g. `containsExactly(1, 2)` which calls `contains.inOrder.only.values(1, 2)`
|
||||
and a second one which expects one or more `assertionCreator`-lambda,
|
||||
e.g. `containsExactly({ isLessThan(0) }, { isGreaterThan(5) })`
|
||||
which calls `contains.inOrder.only.elements({ isLessThan(2) }, { isGreaterThan(5) })`.
|
||||
e.g. `containsExactly( { toBeGreaterThan(5) }, { toBeLessThan(10) })`
|
||||
which calls `contains.inOrder.only.elements({ toBeGreaterThan(5) }, { toBeLessThan(10) })`.
|
||||
We will spare the examples here and show them in the following sections.
|
||||
Notice that you can pass `null` to `containsExactly` instead of an `assertionCreator`-lambda to match `null`.
|
||||
This makes of course only sense if your `Iterable` contains nullable elements.
|
||||
@@ -1064,7 +1072,7 @@ Following each in action:
|
||||
```kotlin
|
||||
expect(listOf(1, 2, 3, 4)).any { toBeLessThan(0) }
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L108)</sub> ↓ <sub>[Output](#ex-collection-any)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L135)</sub> ↓ <sub>[Output](#ex-collection-any)</sub>
|
||||
<a name="ex-collection-any"></a>
|
||||
```text
|
||||
expected that subject: [1, 2, 3, 4] (java.util.Arrays.ArrayList <1234789>)
|
||||
@@ -1081,7 +1089,7 @@ expected that subject: [1, 2, 3, 4] (java.util.Arrays.ArrayList <1234789>
|
||||
```kotlin
|
||||
expect(listOf(1, 2, 3, 4)).none { toBeGreaterThan(2) }
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L111)</sub> ↓ <sub>[Output](#ex-collection-none)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L138)</sub> ↓ <sub>[Output](#ex-collection-none)</sub>
|
||||
<a name="ex-collection-none"></a>
|
||||
```text
|
||||
expected that subject: [1, 2, 3, 4] (java.util.Arrays.ArrayList <1234789>)
|
||||
@@ -1100,7 +1108,7 @@ expected that subject: [1, 2, 3, 4] (java.util.Arrays.ArrayList <1234789>
|
||||
```kotlin
|
||||
expect(listOf(1, 2, 3, 4)).all { toBeGreaterThan(2) }
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L114)</sub> ↓ <sub>[Output](#ex-collection-all)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L141)</sub> ↓ <sub>[Output](#ex-collection-all)</sub>
|
||||
<a name="ex-collection-all"></a>
|
||||
```text
|
||||
expected that subject: [1, 2, 3, 4] (java.util.Arrays.ArrayList <1234789>)
|
||||
@@ -1130,7 +1138,7 @@ Following on the last section we will start with an `inOrder` example:
|
||||
```kotlin
|
||||
expect(listOf(1, 2, 2, 4)).contains.inOrder.only.entries({ toBeLessThan(3) }, { toBeLessThan(2) })
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L118)</sub> ↓ <sub>[Output](#ex-collection-builder-1)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L145)</sub> ↓ <sub>[Output](#ex-collection-builder-1)</sub>
|
||||
<a name="ex-collection-builder-1"></a>
|
||||
```text
|
||||
expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>)
|
||||
@@ -1178,7 +1186,7 @@ and we happily answer your question there.
|
||||
```kotlin
|
||||
expect(listOf(1, 2, 2, 4)).contains.inOrder.only.values(1, 2, 2, 3, 4)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L121)</sub> ↓ <sub>[Output](#ex-collection-builder-2)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L148)</sub> ↓ <sub>[Output](#ex-collection-builder-2)</sub>
|
||||
<a name="ex-collection-builder-2"></a>
|
||||
```text
|
||||
expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>)
|
||||
@@ -1203,7 +1211,7 @@ expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>
|
||||
```kotlin
|
||||
expect(listOf(1, 2, 2, 4)).contains.inAnyOrder.atLeast(1).butAtMost(2).entries({ toBeLessThan(3) })
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L124)</sub> ↓ <sub>[Output](#ex-collection-builder-3)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L151)</sub> ↓ <sub>[Output](#ex-collection-builder-3)</sub>
|
||||
<a name="ex-collection-builder-3"></a>
|
||||
```text
|
||||
expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>)
|
||||
@@ -1220,7 +1228,7 @@ expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>
|
||||
```kotlin
|
||||
expect(listOf(1, 2, 2, 4)).contains.inAnyOrder.only.values(1, 2, 3, 4)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L127)</sub> ↓ <sub>[Output](#ex-collection-builder-4)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L154)</sub> ↓ <sub>[Output](#ex-collection-builder-4)</sub>
|
||||
<a name="ex-collection-builder-4"></a>
|
||||
```text
|
||||
expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>)
|
||||
@@ -1239,7 +1247,7 @@ expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>
|
||||
```kotlin
|
||||
expect(listOf(1, 2, 2, 4)).contains.inAnyOrder.only.values(4, 3, 2, 2, 1)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L130)</sub> ↓ <sub>[Output](#ex-collection-builder-5)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L157)</sub> ↓ <sub>[Output](#ex-collection-builder-5)</sub>
|
||||
<a name="ex-collection-builder-5"></a>
|
||||
```text
|
||||
expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>)
|
||||
@@ -1269,7 +1277,7 @@ and more [Sophisticated Assertion Builder](#sophisticated-assertion-builders-1)
|
||||
```kotlin
|
||||
expect(mapOf("a" to 1, "b" to 2)).contains("c" to 2, "a" to 1, "b" to 1)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L134)</sub> ↓ <sub>[Output](#ex-map-1)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L161)</sub> ↓ <sub>[Output](#ex-map-1)</sub>
|
||||
<a name="ex-map-1"></a>
|
||||
```text
|
||||
expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>)
|
||||
@@ -1293,7 +1301,7 @@ expect(mapOf("a" to 1, "b" to 2)).contains(
|
||||
KeyValue("b") { toBeLessThan(2) }
|
||||
)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L137)</sub> ↓ <sub>[Output](#ex-map-2)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L164)</sub> ↓ <sub>[Output](#ex-map-2)</sub>
|
||||
<a name="ex-map-2"></a>
|
||||
```text
|
||||
expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>)
|
||||
@@ -1315,7 +1323,7 @@ Again both overloads are provided, one for key-value `Pair`s:
|
||||
```kotlin
|
||||
expect(mapOf("a" to 1, "b" to 2)).containsOnly("b" to 2)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L145)</sub> ↓ <sub>[Output](#ex-map-only-1)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L172)</sub> ↓ <sub>[Output](#ex-map-only-1)</sub>
|
||||
<a name="ex-map-only-1"></a>
|
||||
```text
|
||||
expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>)
|
||||
@@ -1340,7 +1348,7 @@ expect(mapOf("a" to 1, "b" to 2)).containsOnly(
|
||||
KeyValue("b") { toBeLessThan(2) }
|
||||
)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L148)</sub> ↓ <sub>[Output](#ex-map-only-2)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L175)</sub> ↓ <sub>[Output](#ex-map-only-2)</sub>
|
||||
<a name="ex-map-only-2"></a>
|
||||
```text
|
||||
expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>)
|
||||
@@ -1368,7 +1376,7 @@ again provide two overloads, one expecting key-value `Pair`s:
|
||||
```kotlin
|
||||
expect(mapOf("a" to 1, "b" to 2)).contains.inOrder.only.entries("b" to 2, "a" to 1)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L156)</sub> ↓ <sub>[Output](#ex-map-builder-1)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L183)</sub> ↓ <sub>[Output](#ex-map-builder-1)</sub>
|
||||
<a name="ex-map-builder-1"></a>
|
||||
```text
|
||||
expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>)
|
||||
@@ -1395,7 +1403,7 @@ expect(mapOf("a" to 1, "b" to 2)).contains.inOrder.only.entries(
|
||||
KeyValue("a") { toBeLessThan(2) },
|
||||
KeyValue("b") { toBeLessThan(2) })
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L159)</sub> ↓ <sub>[Output](#ex-map-builder-2)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L186)</sub> ↓ <sub>[Output](#ex-map-builder-2)</sub>
|
||||
<a name="ex-map-builder-2"></a>
|
||||
```text
|
||||
expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>)
|
||||
@@ -1432,7 +1440,7 @@ expect(mapOf("bernstein" to bernstein))
|
||||
feature { f(it::firstName) }.toEqual("Albert")
|
||||
}
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L169)</sub> ↓ <sub>[Output](#ex-map-3)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L196)</sub> ↓ <sub>[Output](#ex-map-3)</sub>
|
||||
<a name="ex-map-3"></a>
|
||||
```text
|
||||
expected that subject: {bernstein=Person(firstName=Leonard, lastName=Bernstein, age=50)} (java.util.Collections.SingletonMap <1234789>)
|
||||
@@ -1452,7 +1460,7 @@ expect(mapOf("a" to 1, "b" to 2)) {
|
||||
values { none { toBeGreaterThan(1) } }
|
||||
}
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L181)</sub> ↓ <sub>[Output](#ex-map-4)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L208)</sub> ↓ <sub>[Output](#ex-map-4)</sub>
|
||||
<a name="ex-map-4"></a>
|
||||
```text
|
||||
expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>)
|
||||
@@ -1490,7 +1498,7 @@ expect(linkedMapOf("a" to 1, "b" to 2)).asEntries().contains.inOrder.only.entrie
|
||||
}
|
||||
)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L187)</sub> ↓ <sub>[Output](#ex-map-5)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L214)</sub> ↓ <sub>[Output](#ex-map-5)</sub>
|
||||
<a name="ex-map-5"></a>
|
||||
```text
|
||||
expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>)
|
||||
@@ -1586,7 +1594,7 @@ expect("filename?")
|
||||
notToContain("?")
|
||||
}
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L197)</sub> ↓ <sub>[Output](#ex-because-1)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L224)</sub> ↓ <sub>[Output](#ex-because-1)</sub>
|
||||
<a name="ex-because-1"></a>
|
||||
```text
|
||||
expected that subject: "filename?" <1234789>
|
||||
@@ -1842,7 +1850,7 @@ But Atrium shows where it goes wrong and even gives a possible hint:
|
||||
|
||||
```text
|
||||
expected that subject: 9.99 (kotlin.Float <1234789>)
|
||||
◆ to be (error ± 0.01): 10.0 (kotlin.Float <1234789>)
|
||||
◆ to equal (error ± 0.01): 10.0 (kotlin.Float <1234789>)
|
||||
» failure might be due to using kotlin.Float, see exact check on the next line
|
||||
» exact check is |9.989999771118164 - 10.0| = 0.010000228881835938 ≤ 0.009999999776482582
|
||||
```
|
||||
@@ -1863,10 +1871,10 @@ expect {
|
||||
}
|
||||
}.toThrow<IllegalStateException> { messageContains("no no no") }
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L210)</sub> ↓ <sub>[Output](#ex-add-info-3)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L237)</sub> ↓ <sub>[Output](#ex-add-info-3)</sub>
|
||||
<a name="ex-add-info-3"></a>
|
||||
```text
|
||||
expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$35$1 <1234789>)
|
||||
expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$39$1 <1234789>)
|
||||
◆ ▶ thrown exception when called: java.lang.IllegalArgumentException
|
||||
◾ is instance of type: IllegalStateException (java.lang.IllegalStateException)
|
||||
» ▶ message:
|
||||
@@ -1878,14 +1886,14 @@ expected that subject: () -> kotlin.Nothing (readme.examples.MostExamples
|
||||
ℹ Properties of the unexpected IllegalArgumentException
|
||||
» message: "no no no..." <1234789>
|
||||
» stacktrace:
|
||||
⚬ readme.examples.MostExamplesSpec$1$35$1.invoke(MostExamplesSpec.kt:215)
|
||||
⚬ readme.examples.MostExamplesSpec$1$35$1.invoke(MostExamplesSpec.kt:22)
|
||||
⚬ readme.examples.MostExamplesSpec$1$35.invoke(MostExamplesSpec.kt:239)
|
||||
⚬ readme.examples.MostExamplesSpec$1$35.invoke(MostExamplesSpec.kt:22)
|
||||
⚬ readme.examples.MostExamplesSpec$1$39$1.invoke(MostExamplesSpec.kt:242)
|
||||
⚬ readme.examples.MostExamplesSpec$1$39$1.invoke(MostExamplesSpec.kt:22)
|
||||
⚬ readme.examples.MostExamplesSpec$1$39.invoke(MostExamplesSpec.kt:266)
|
||||
⚬ readme.examples.MostExamplesSpec$1$39.invoke(MostExamplesSpec.kt:22)
|
||||
» cause: java.lang.UnsupportedOperationException
|
||||
» message: "not supported" <1234789>
|
||||
» stacktrace:
|
||||
⚬ readme.examples.MostExamplesSpec$1$35$1.invoke(MostExamplesSpec.kt:213)
|
||||
⚬ readme.examples.MostExamplesSpec$1$39$1.invoke(MostExamplesSpec.kt:240)
|
||||
```
|
||||
</ex-add-info-3>
|
||||
|
||||
@@ -1906,7 +1914,7 @@ then Atrium reminds us of the possible pitfall. For instance:
|
||||
```kotlin
|
||||
expect(BigDecimal.TEN).isEqualIncludingScale(BigDecimal("10.0"))
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L220)</sub> ↓ <sub>[Output](#ex-pitfall-1)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L247)</sub> ↓ <sub>[Output](#ex-pitfall-1)</sub>
|
||||
<a name="ex-pitfall-1"></a>
|
||||
```text
|
||||
expected that subject: 10 (java.math.BigDecimal <1234789>)
|
||||
@@ -1924,7 +1932,7 @@ For instance:
|
||||
```kotlin
|
||||
expect(listOf(1)).get(0) {}
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L223)</sub> ↓ <sub>[Output](#ex-pitfall-2)</sub>
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L250)</sub> ↓ <sub>[Output](#ex-pitfall-2)</sub>
|
||||
<a name="ex-pitfall-2"></a>
|
||||
```text
|
||||
expected that subject: [1] (java.util.Collections.SingletonList <1234789>)
|
||||
|
||||
@@ -26,6 +26,17 @@ class MostExamplesSpec : Spek({
|
||||
expect(4 + 6).toBeLessThan(5).toBeGreaterThan(10)
|
||||
}
|
||||
|
||||
fun codeSingleNotExecutedHenceDoesNotFail() {
|
||||
//snippet-code-single-start
|
||||
expect(4 + 6).toBeLessThan(5)
|
||||
expect(4 + 6).toBeGreaterThan(10)
|
||||
//snippet-code-single-end
|
||||
}
|
||||
|
||||
test("code-single-explained"){
|
||||
//snippet-code-single-insert
|
||||
}
|
||||
|
||||
test("ex-group") {
|
||||
// assertion group with two assertions, both evaluated
|
||||
expect(4 + 6) {
|
||||
@@ -34,6 +45,22 @@ class MostExamplesSpec : Spek({
|
||||
}
|
||||
}
|
||||
|
||||
fun codeAndNotExecutedHenceDoesNotFail() {
|
||||
//snippet-code-and-start
|
||||
expect(5) {
|
||||
// ...
|
||||
} and { // if the previous block fails, then this one is not evaluated
|
||||
// ...
|
||||
}
|
||||
//snippet-code-and-end
|
||||
}
|
||||
|
||||
test("code-and"){
|
||||
expect(5).toBeGreaterThan(2).and.toBeLessThan(10)
|
||||
|
||||
//snippet-code-and-insert
|
||||
}
|
||||
|
||||
test("ex-toThrow1") {
|
||||
expect {
|
||||
// this block does something but eventually...
|
||||
|
||||
Reference in New Issue
Block a user