brian-watkins/elm-spec/1.0.0

NOTE: the latest version is 3.3.2

Spec.Http

Observe, and make claims about HTTP requests during a spec.

Observe HTTP Requests

type alias HttpRequest =
{ url : String
, headers : Dict String String
, body : RequestBody
}

Represents an HTTP request made by the program in the course of the scenario.

Represents the body of an HTTP request.

observeRequests : HttpRoute -> Observer model (List HttpRequest)

Observe HTTP requests that match the given route.

For example:

Spec.Http.observeRequests (Spec.Http.Route.get "http://fake.com/fake")
  |> Spec.Claim.isList
    [ Spec.Http.hasHeader ("Authorization", "Bearer some-fun-token")
    ]

Make Claims About HTTP Requests

hasHeader : ( String, String ) -> HttpRequest -> Verdict

Claim that an HTTP request has a header with the given (key, value) tuple.

For example, if the observed request has an Authorization header with the value Bearer some-fun-token, then the following claim:

Spec.Http.hasHeader ("Authorization", "Bearer some-fun-token")

would be accepted.

hasStringBody : String -> HttpRequest -> Verdict

Claim that the body of an HTTP request is a string that is equal to the given value.

hasJsonBody : Decoder a -> Claim a -> HttpRequest -> Verdict

Claim that the body of an HTTP request is a string that can be decoded with the given decoder into a value that satisfies the given claim.

For example, if the body of the observed request was {"sport":"bowling"}, then the following claim:

Spec.Http.hasJsonBody (Json.Decode.field "sport" Json.Decode.string)
  (Spec.Claim.isEqualTo Debug.toString "bowling")

would be accepted.