Skip to content

Commit

Permalink
Fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosedp committed Feb 8, 2024
1 parent 71ac62d commit efab826
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package io.restassured.module.scala.extensions
import scala.util.chaining.*
import scala.reflect.ClassTag
import io.restassured.RestAssured.`given`
import io.restassured.RestAssured.`when`
import io.restassured.response.{ExtractableResponse, Response, ValidatableResponse}
import io.restassured.specification.{RequestSender, RequestSpecification}
import io.restassured.specification.RequestSpecification
import io.restassured.internal.{ValidatableResponseImpl, ResponseSpecificationImpl}

// Main wrappers
Expand Down Expand Up @@ -75,25 +74,6 @@ extension (spec: RequestSpecification)
infix def When(block: RequestSpecification => Response): Response =
spec.`when`().pipe(block)

/**
* A wrapper around [io.restassured.RestAssured.when] to start building the DSL
* expression by sending a request without any parameters or headers etc. E.g.
* {{{
* Given()
* .When(_.get("/x"))
* .Then(_.body("x.y.z1", equalTo("Z1")))
* }}}
* Note that if you need to add parameters, headers, cookies or other request
* properties use the [[Given()]] method.
*
* @see
* io.restassured.RestAssured.when
* @return
* A request sender interface that let's you call resources on the server
*/
def When(block: RequestSender => Response): Response =
`when`().pipe(block)

/**
* A wrapper around [then] that lets you validate the response. Usage example:
* {{{
Expand Down Expand Up @@ -170,4 +150,7 @@ extension [T](resp: ValidatableResponse)
// End main wrappers

private def doIfValidatableResponseImpl(fn: ResponseSpecificationImpl => Unit): ValidatableResponse => Unit =
resp => if resp.isInstanceOf[ValidatableResponseImpl] then fn(resp.asInstanceOf[ValidatableResponseImpl].responseSpec)
resp =>
resp match
case resp: ValidatableResponseImpl => fn(resp.responseSpec)
case _ => ()
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import io.restassured.builder.ResponseBuilder
import io.restassured.filter.Filter
import io.restassured.http.ContentType.JSON
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.catchThrowable
import org.hamcrest.Matchers.*
import org.junit.Before
import org.junit.Test
Expand Down Expand Up @@ -141,7 +140,15 @@ class RestAssuredScalaExtensionsTest:
)
} catch {
case e: AssertionError =>
assertThat(e).hasMessage("""1 expectation failed.
assertThat(e).hasMessage("""3 expectations failed.
|Expected status code <400> but was <200>.
|
|JSON path message doesn't match.
|Expected: Another World
| Actual: Hello World
|
|JSON path message doesn't match.
|Expected: Brave new world
| Actual: Hello World
|""".stripMargin)
}

0 comments on commit efab826

Please sign in to comment.