Mocking HTTP services on spray can for integration testing
Pre-canned helps you to mock out the HTTP services your application depends on. This can be especially useful for your integration testing.
For SBT add the dependency "com.netaporter" %% "pre-canned" % "0.0.4" % "test"
Pre-canned currently comes in two flavours:
Help make Pre-canned better and submit a new improved flavour via a PR, or ideas for one in an issue.
There are a basic set of expectations and canned responses. Feel free to contribute more via a PR.
import com.netaporter.precanned.dsl.basic._
val animalApi = httpServerMock(system).bind(8765).block
animalApi.expect(get, path("/animals"), query("name" -> "giraffe"))
.andRespondWith(resource("/responses/giraffe.json"))
import com.netaporter.precanned.dsl.fancy._
val animalApi = httpServerMock(system).bind(8766).block
animalApi expect
get and path("/animals") and query("name" -> "giraffe") and
respond using
resource("/responses/giraffe.json") end()