trait SimplerZIOMockMigration extends AnyRef
Can simplify migration from zio-mock to scalamock. Not needed when writing tests on scalamock from scratch.
- Alphabetic
- By Inheritance
- SimplerZIOMockMigration
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native() @HotSpotIntrinsicCandidate()
-
macro
def
createMockedLayer[A](expectations: URIO[A, Any])(implicit tag: Tag[A]): ULayer[A]
Creates a layer that creates a new mock.
Creates a layer that creates a new mock.
WARN: use with caution, provide only one Layer of each type!
In zio-mock there's an implicit conversion from Expectation[A] to ULayer[A]. In scalamock, instead of Expectation, URIO[A, Any] can be used. To avoid rewriting the passing of expectations to layers, an analogous conversion is defined.
It's not declared as implicit to avoid unnecessary bugs, it has to be called manually.
WARN: when passing effects to layers carelessly, unexpected behavior can occur: creation of mocks that we didn't want to create.
Example:
test("creation of two mocks") { val layer1 = createMockedLayer( ZIO.serviceWith[Service] { mock => (mock.f _).expects(42).returnsZIO("-42") } ) val layer2 = createMockedLayer( ZIO.serviceWith[Service] { mock => (mock.f _).expects(43).returnsZIO("-43") } ) val effect = for { _ <- ZIO.serviceWith[Service] { mock => (mock.f _).expects(42).returnsZIO("-42") } value <- ZIO.serviceWithZIO[Service](_.f(42)) } yield assertTrue(value == "-42") effect.provideLayer(layer1 ++ layer2) }
In this test, two mocks are created — one expects to be called with an argument 42, and the second — with an argument 43 (and probably creating TWO mocks is not what the developer wanted).
So when writing tests on scalamock from scratch, it's not recommended to use this conversion (and the trait SimplerZIOMockMigration, in general). Only for simplifying the migration from zio-mock to scalamock.
Moreover, in some cases, when there's no complex logic on layers in the test, it's possible to migrate without this trait, if you get rid of passing expectations to layers.
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
Deprecated Value Members
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] ) @Deprecated
- Deprecated