Skip to content

Instantly share code, notes, and snippets.

@saamalik
Created November 20, 2016 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saamalik/2bfe2fe4075dc05b9f508199087cd88e to your computer and use it in GitHub Desktop.
Save saamalik/2bfe2fe4075dc05b9f508199087cd88e to your computer and use it in GitHub Desktop.
ReactiveMongo 0.12 + ScalaTest WordSpec
val reactiveMongo = "org.reactivemongo" %% "play2-reactivemongo" % "0.12.0"
val scalatest = "org.scalatest" %% "scalatest" % "3.0.0" % "test"
lazy val root = (project in file(".")).
enablePlugins(PlayScala).
settings(
organization := "com.cisco",
version := "1.0-SNAPSHOT",
scalaVersion := "2.11.8",
scalacOptions in ThisBuild ++= Seq("-feature", "-language:implicitConversions"),
libraryDependencies ++= Seq(reactiveMongo, scalatest)
)
import org.scalatest.{AsyncWordSpec, Matchers}
import play.api.libs.json._
import reactivemongo.api.{Cursor, MongoDriver, ReadPreference}
import reactivemongo.play.json._
import reactivemongo.play.json.collection.JSONCollection
import scala.concurrent.Future
class ExampleSpec extends AsyncWordSpec with Matchers {
val driver = new MongoDriver
val connection = driver.connection(Seq("192.168.99.100"))
val db = connection.database("db")
def col(name: String = "city"): Future[JSONCollection] = db.map(_.collection[JSONCollection](name))
"City collection" should {
"have size 19" in {
col().flatMap(
_.find(Json.obj()).
cursor[JsObject](ReadPreference.primary).
collect[Seq](-1, Cursor.FailOnError[Seq[JsObject]]())
).map {_ should have size 19}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment