Skip to content

Commit

Permalink
Use & to chain extractors in expecting statements
Browse files Browse the repository at this point in the history
Change assert to asserting
  • Loading branch information
IainHull committed Oct 22, 2013
1 parent e4ac669 commit bc56d90
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/org/iainhull/resttest/Dsl.scala
Expand Up @@ -33,7 +33,7 @@ object Dsl extends Extractors {
proc(builder)
}

def assert(assertions: Assertion*)(implicit driver: Driver): Response = {
def asserting(assertions: Assertion*)(implicit driver: Driver): Response = {
val res = execute()
val assertionResults = for {
a <- assertions
Expand Down
48 changes: 24 additions & 24 deletions src/test/scala/org/iainhull/resttest/DslSpec.scala
Expand Up @@ -121,47 +121,47 @@ class DslSpec extends FlatSpec with ShouldMatchers {

it should "support asserting values equals check" in {
using(_ url "http://api.rest.org/person/") { implicit rb =>
GET assert (StatusCode === Status.OK)
GET asserting (StatusCode === Status.OK)
driver.lastRequest should have('method(GET), 'url(new URI("http://api.rest.org/person/")))

GET assert (Header("X-Person-Id") === "1234")
GET asserting (Header("X-Person-Id") === "1234")

val e = evaluating { GET assert (StatusCode === Status.Created) } should produce[AssertionError]
val e = evaluating { GET asserting (StatusCode === Status.Created) } should produce[AssertionError]
driver.lastRequest should have('method(GET), 'url(new URI("http://api.rest.org/person/")))
e should have('message("statusCode: 200 did not equal 201"))
}
}

it should "support asserting values not-equals check" in {
using(_ url "http://api.rest.org/person/") { implicit rb =>
GET assert (StatusCode !== Status.Created)
GET asserting (StatusCode !== Status.Created)
driver.lastRequest should have('method(GET), 'url(new URI("http://api.rest.org/person/")))

GET assert (Header("X-Person-Id") !== "999")
GET asserting (Header("X-Person-Id") !== "999")

val e = evaluating { GET assert (StatusCode !== Status.OK) } should produce[AssertionError]
val e = evaluating { GET asserting (StatusCode !== Status.OK) } should produce[AssertionError]
e should have('message("statusCode: 200 did equal 200"))
}
}

it should "support asserting values in check" in {
using(_ url "http://api.rest.org/person/") { implicit rb =>
GET assert (StatusCode in (Status.OK, Status.Created))
GET asserting (StatusCode in (Status.OK, Status.Created))
driver.lastRequest should have('method(GET), 'url(new URI("http://api.rest.org/person/")))

val e = evaluating { GET assert (StatusCode in (Status.Created, Status.Accepted)) } should produce[AssertionError]
val e = evaluating { GET asserting (StatusCode in (Status.Created, Status.Accepted)) } should produce[AssertionError]
e should have('message("statusCode: 200 was not in (201, 202)"))
}
}

it should "support asserting values Ordered comparison operator checks" in {
using(_ url "http://api.rest.org/person/") { implicit rb =>
GET assert (StatusCode > 1)
GET assert (StatusCode >= 1)
GET assert (StatusCode < 299)
GET assert (StatusCode <= 299)
GET asserting (StatusCode > 1)
GET asserting (StatusCode >= 1)
GET asserting (StatusCode < 299)
GET asserting (StatusCode <= 299)

val e = evaluating { GET assert (StatusCode > 999) } should produce[AssertionError]
val e = evaluating { GET asserting (StatusCode > 999) } should produce[AssertionError]
driver.lastRequest should have('method(GET), 'url(new URI("http://api.rest.org/person/")))
e should have('message("statusCode: 200 was not greater than 999"))
}
Expand Down Expand Up @@ -278,13 +278,13 @@ class DslSpec extends FlatSpec with ShouldMatchers {
Nil

RequestBuilder() url "http://api.rest.org/person" apply { implicit rb =>
GET assert (StatusCode === Status.OK, jsonBodyAsList[Person] === EmptyList)
val id = POST body personJson assert (StatusCode === Status.Created) returning (Header("X-Person-Id"))
GET / id assert (StatusCode === Status.OK, jsonBodyAs[Person] === Jason)
GET assert (StatusCode === Status.OK, jsonBodyAsList[Person] === Seq(Jason))
DELETE / id assert (StatusCode === Status.OK)
GET / id assert (StatusCode === Status.NotFound)
GET assert (StatusCode === Status.OK, jsonBodyAsList[Person] === EmptyList)
GET asserting (StatusCode === Status.OK, jsonBodyAsList[Person] === EmptyList)
val id = POST body personJson asserting (StatusCode === Status.Created) returning (Header("X-Person-Id"))
GET / id asserting (StatusCode === Status.OK, jsonBodyAs[Person] === Jason)
GET asserting (StatusCode === Status.OK, jsonBodyAsList[Person] === Seq(Jason))
DELETE / id asserting (StatusCode === Status.OK)
GET / id asserting (StatusCode === Status.NotFound)
GET asserting (StatusCode === Status.OK, jsonBodyAsList[Person] === EmptyList)
}
}

Expand All @@ -307,16 +307,16 @@ class DslSpec extends FlatSpec with ShouldMatchers {

using(_ url "http://api.rest.org/person") { implicit rb =>
GET expecting {
case StatusCode(Status.OK) ~ BodyAsPersonList(EmptyList) =>
case StatusCode(Status.OK) & BodyAsPersonList(EmptyList) =>
}
val id = POST body personJson expecting {
case StatusCode(Status.Created) ~ PersonIdHeader(id) => id
}
GET / id expecting {
case StatusCode(Status.OK) ~ BodyAsPerson(p) => p should be(Jason)
case StatusCode(Status.OK) & BodyAsPerson(p) => p should be(Jason)
}
GET expecting {
case StatusCode(Status.OK) ~ BodyAsPersonList(xp) => xp should be (Seq(Jason))
case StatusCode(Status.OK) & BodyAsPersonList(xp) => xp should be (Seq(Jason))
}
DELETE / id expecting {
case StatusCode(Status.OK) =>
Expand All @@ -325,7 +325,7 @@ class DslSpec extends FlatSpec with ShouldMatchers {
case StatusCode(Status.NotFound) =>
}
GET expecting {
case StatusCode(Status.OK) ~ BodyAsPersonList(EmptyList) =>
case StatusCode(Status.OK) & BodyAsPersonList(EmptyList) =>
}
}
}
Expand Down

0 comments on commit bc56d90

Please sign in to comment.