Created
November 20, 2016 21:27
-
-
Save saamalik/2bfe2fe4075dc05b9f508199087cd88e to your computer and use it in GitHub Desktop.
ReactiveMongo 0.12 + ScalaTest WordSpec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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