diff --git a/playtest-http/src/main/kotlin/com/uzabase/playtest2/http/proxy/ResponseBodyProxy.kt b/playtest-http/src/main/kotlin/com/uzabase/playtest2/http/proxy/ResponseBodyProxy.kt index 2f8d005..b7a0e71 100644 --- a/playtest-http/src/main/kotlin/com/uzabase/playtest2/http/proxy/ResponseBodyProxy.kt +++ b/playtest-http/src/main/kotlin/com/uzabase/playtest2/http/proxy/ResponseBodyProxy.kt @@ -11,19 +11,23 @@ class ResponseBodyProxy private constructor(val body: Path) : ShouldBeString, Sh } // FIXME need more explained - override fun shouldBe(expected: String): TestResult = - if (body.toFile().readText(Charsets.UTF_8) == expected) { + override fun shouldBe(expected: String): TestResult { + val actual = body.toFile().readText(Charsets.UTF_8) + return if (actual == expected) { Ok } else { - Failed { simpleExplain(expected, body) } + Failed { simpleExplain(expected, actual) } } + } - override fun shouldContain(expected: String): TestResult = - if (body.toFile().readText(Charsets.UTF_8).contains(expected)) { + override fun shouldContain(expected: String): TestResult { + val actual = body.toFile().readText(Charsets.UTF_8) + return if (actual.contains(expected)) { Ok } else { - Failed { simpleExplain(expected, body) } + Failed { simpleExplain(expected, actual) } } + } override fun toJsonPathProxy(path: String): JsonPathProxy = body.toFile().readText(Charsets.UTF_8) diff --git a/playtest-http/src/test/kotlin/com/uzabase/playtest2/http/proxy/ResponseBodyProxyTest.kt b/playtest-http/src/test/kotlin/com/uzabase/playtest2/http/proxy/ResponseBodyProxyTest.kt index d912f94..dba1104 100644 --- a/playtest-http/src/test/kotlin/com/uzabase/playtest2/http/proxy/ResponseBodyProxyTest.kt +++ b/playtest-http/src/test/kotlin/com/uzabase/playtest2/http/proxy/ResponseBodyProxyTest.kt @@ -37,8 +37,8 @@ class ResponseBodyProxyTest : FunSpec({ | value: Hello, world!! | class: kotlin.String |Actual: - | value: [^\s]+/com/uzabase/playtest2/http/proxy/response-body.txt - | class: sun.nio.fs.UnixPath + | value: Hello, world + | class: kotlin.String """.trimMargin() ) } @@ -50,9 +50,19 @@ class ResponseBodyProxyTest : FunSpec({ } test("should not contain") { - fromClasspathToResponseBodyProxy("com/uzabase/playtest2/http/proxy/response-body.txt") + val result = fromClasspathToResponseBodyProxy("com/uzabase/playtest2/http/proxy/response-body.txt") .shouldContain("world!!") - .shouldBeInstanceOf() + result.shouldBeInstanceOf() + result.explain().shouldMatch( + """ + |Expected: + | value: world!! + | class: kotlin.String + |Actual: + | value: Hello, world + | class: kotlin.String + """.trimMargin() + ) } }