From 0b9580eba18115d32e8029cb96cf7e0f380989f3 Mon Sep 17 00:00:00 2001 From: Daisuke Itakura Date: Sat, 12 Jul 2025 10:08:33 +0900 Subject: [PATCH] =?UTF-8?q?=E5=A4=B1=E6=95=97=E6=99=82=E3=81=AE=E3=83=A1?= =?UTF-8?q?=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=81=AB=E5=AE=9F=E9=9A=9B?= =?UTF-8?q?=E3=81=AE=E5=80=A4=E3=82=92=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../playtest2/http/proxy/ResponseBodyProxy.kt | 16 ++++++++++------ .../http/proxy/ResponseBodyProxyTest.kt | 18 ++++++++++++++---- 2 files changed, 24 insertions(+), 10 deletions(-) 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() + ) } }