Repository navigation
v0.29.0
0.29.0 - 2023-02-11
New Feature
- Add [
extras-testing-tools] and [extras-testing-tools-cats] with tools to use stub (#307)
extras-testing-tools
import extras.testing.StubTools
trait TestType {
def foo(n: Int): Int
}
object TestTypeStub {
def apply(f: => Option[Int => Int]): TestType = new TestType {
override def foo(n: Int): Int =
f.fold[Int](throw StubTools.missing)(_(n))
}
}If the stub function is missing, it will throw a MissingStubException saying where the missing stub is.
For example,
TestTypeStub(None)results in
>> Missing Stub implementation at
>> extras.testing.TestTypeStub$$anon$1.$anonfun$foo$1(TestType.scala:11)
>> ---
>> Details:
>> extras.testing.TestTypeStub$$anon$1.$anonfun$foo$1(TestType.scala:11)
at scala.Option.fold(Option.scala:263)
at extras.testing.TestTypeStub$$anon$1.foo(TestType.scala:11)
at extras.testing.StubToolsSpec$.$anonfun$testMissingMissingCase$2(StubToolsSpec.scala:33)
...
extras-testing-tools-cats
import cats._
import cats.syntax.all._
import extras.testing.StubToolsCats
trait TestType[F[*]] {
def foo(n: Int): F[Int]
def bar(n: Int): F[Int]
}
object TestTypeStub {
def apply[F[*]: MonadThrow](f4Foo: => Option[Int => Int], f4Bar: => Option[Int => F[Int]]): TestType[F] =
new TestType[F] {
override def foo(n: Int): F[Int] =
StubToolsCats.stub(f4Foo).map(_(n))
override def bar(n: Int): F[Int] =
StubToolsCats.stub(f4Bar).flatMap(_(n))
}
}If the stub function is missing, it will be F containing MissingStubException saying where the missing stub is.
For example, the following code
val testType = TestTypeStub[IO](none, f.some)
testType.foo(n).attempt // Either[Throwable, Int]results in IO[Either[Throwable, Int]] where Either is Left(MissingStubException) with the information like the following.
>> Missing Stub implementation at
>> extras.testing.TestTypeStub$$anon$1.$anonfun$foo$1(TestType.scala:16)
>> ---
>> Details:
>> extras.testing.TestTypeStub$$anon$1.$anonfun$foo$1(TestType.scala:16)
at cats.ApplicativeError.fromOption(ApplicativeError.scala:318)
at cats.ApplicativeError.fromOption$(ApplicativeError.scala:315)
at cats.effect.IOLowPriorityInstances$IOEffect.fromOption(IO.scala:865)
at extras.testing.StubToolsCats$StubToolsCatsPartiallyApplied$.$anonfun$apply$1(StubToolsCats.scala:24)
...
Internal Housekeeping
- Upgrade
effectieto2.0.0-beta5(#310)
What's Changed
- Close #307 - Add
extras-testing-toolsandextras-testing-tools-catswith tools to use stub by @kevin-lee in #308 - Update build.sbt - remove unnecessary duplicate libraries by @kevin-lee in #309
- Add hedgehog-extra and update tests for doobie-tools by @kevin-lee in #311
- Close #310 - Upgrade
effectieto2.0.0-beta5by @kevin-lee in #312 - extras v0.29.0 by @kevin-lee in #313
Full Changelog: v0.28.0...v0.29.0