Permalink
Browse files

Improvements to teskit for simplifying tests using action-based queri…

…es (#1544)

Improvements to teskit for simplifying tests using action-based queries
Added shouldYield operator so that we can now have
query shouldYield aValue instead of query.map(_ shouldBe aValue)
query shouldYield Set(...) instead of query.map(_.toSet shouldBe Set(...))
Similarly for Seq and List
  • Loading branch information...
1 parent 898cb18 commit a0eb1ee1a06cac2b34680a3be9abdc478ce2b953 Ashutosh Agarwal committed on GitHub Jul 8, 2016
@@ -115,13 +115,13 @@ class PlainSQLTest extends AsyncTest[JdbcTestDB] {
create.map(_ shouldBe 0),
DBIO.fold((for {
(id, name) <- List((1, "szeiger"), (0, "admin"), (2, "guest"), (3, "foo"))
- } yield sqlu"insert into USERS values ($id, $name)"), 0)(_ + _).map(_ shouldBe 4),
- sql"select id from USERS".as[Int].map(_.toSet shouldBe Set(0,1,2,3)), //TODO Support `to` in Plain SQL Actions
- userForID(2).map(_.head shouldBe User(2,"guest")), //TODO Support `head` and `headOption` in Plain SQL Actions
- s1.map(_ shouldBe List(1)),
- s2.map(_ shouldBe List(2)),
- userForIdAndName(2, "guest").map(_.head shouldBe User(2,"guest")), //TODO Support `head` and `headOption` in Plain SQL Actions
- userForIdAndName(2, "foo").map(_.headOption shouldBe None) //TODO Support `head` and `headOption` in Plain SQL Actions
+ } yield sqlu"insert into USERS values ($id, $name)"), 0)(_ + _) shouldYield(4),
+ sql"select id from USERS".as[Int] shouldYield Set(0,1,2,3), //TODO Support `to` in Plain SQL Actions
+ userForID(2).head shouldYield User(2,"guest"), //TODO Support `head` and `headOption` in Plain SQL Actions
+ s1 shouldYield List(1),
+ s2 shouldYield List(2),
+ userForIdAndName(2, "guest").head shouldYield User(2,"guest"), //TODO Support `head` and `headOption` in Plain SQL Actions
+ userForIdAndName(2, "foo").headOption shouldYield None //TODO Support `head` and `headOption` in Plain SQL Actions
)
}
}
@@ -366,4 +366,14 @@ abstract class AsyncTest[TDB >: Null <: TestDB](implicit TdbClass: ClassTag[TDB]
if(!f.isDefinedAt(x)) fixStack(Assert.fail("Value does not match expected shape: "+x))
}
}
+
+ implicit class DBIOActionExtensionMethods[T, +S <: NoStream, -E <: Effect](action: DBIOAction[T, S, E]) {
+ @inline def shouldYield(t: T) = action.map(_.shouldBe(t))
+ }
+
+ implicit class CollectionDBIOActionExtensionMethods[T, +S <: NoStream, -E <: Effect](action: DBIOAction[Vector[T], S, E]) {
+ @inline def shouldYield(t: Set[T]) = action.map(_.toSet.shouldBe(t))
+ @inline def shouldYield(t: Seq[T]) = action.map(_.toSeq.shouldBe(t))
+ @inline def shouldYield(t: List[T]) = action.map(_.toList.shouldBe(t))
+ }
}

0 comments on commit a0eb1ee

Please sign in to comment.