-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixed zio-mock documentation on mocking collaborators compose layers #7600
fixed zio-mock documentation on mocking collaborators compose layers #7600
Conversation
Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use mdoc
here so we check that these code snippets compile as part of CI?
@@ -916,7 +927,6 @@ test("effectful expectation") { | |||
Random | |||
.nextUUID | |||
.map(id => User(id.toString, s"name-$n")) | |||
.provideLayer(Random.live) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check this gist when reviewing this change.
https://gist.github.com/JoaquinIglesiasTurina/10d16eed4ab774171525673f3087d8e8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
docs/ecosystem/officials/zio-mock.md
Outdated
@@ -67,7 +67,12 @@ case class UserServiceLive(emailService: EmailService, userRepository: UserRepos | |||
|
|||
object UserServiceLive { | |||
val layer: URLayer[EmailService with UserRepository, UserService] = | |||
(UserServiceLive.apply _).toLayer[UserService] | |||
ZLayer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can just be ZLayer.fromFunction
.
docs/ecosystem/officials/zio-mock.md
Outdated
new EmailService { | ||
override def send(to: String, body: String): IO[String, Unit] = | ||
proxy(Send, to, body) | ||
ZLayer.fromZIO( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ZLayer.apply
and use of a for comprehension would be more idiomatic here.
docs/ecosystem/officials/zio-mock.md
Outdated
new UserRepository { | ||
override def save(user: User): IO[String, Unit] = | ||
proxy(Save, user) | ||
ZLayer.fromZIO( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.
docs/ecosystem/officials/zio-mock.md
Outdated
@@ -980,7 +996,7 @@ There are also `failureF` and `failureZIO` variants like what we described for ` | |||
|
|||
This expectation simulates a never-ending loop: | |||
|
|||
```scala | |||
```scala mdoc/silent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to add mdoc
to all of these to make sure they compile. I think this could use one more pass to make sure all the examples are as idiomatic as possible and then will be good to go!
I've reviewed the |
docs/ecosystem/officials/zio-mock.md
Outdated
ZLayer { | ||
for { | ||
proxy <- ZIO.service[Proxy] | ||
} yield ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor but this will be slightly more readable if you delete the parentheses here and define new EmailService
on the same line. } yield new EmailService {
docs/ecosystem/officials/zio-mock.md
Outdated
ZLayer { | ||
for { | ||
proxy <- ZIO.service[Proxy] | ||
} yield ( | ||
new UserRepository { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.
docs/ecosystem/officials/zio-mock.md
Outdated
ZLayer( | ||
for { | ||
proxy <- ZIO.service[Proxy] | ||
} yield { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can delete extra curly braces and move to same line.
import zio.test._ | ||
import MockPolyService._ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could keep the import and just do PolyInput.of[String]
. This would probably be slightly cleaner.
docs/ecosystem/officials/zio-mock.md
Outdated
def polyError[E: Tag](input: Int) = proxy(PolyError.of[E], input) | ||
def polyOutput[A: Tag](input: Int) = proxy(PolyOutput.of[A], input) | ||
def polyAll[I: Tag, E: Tag, A: Tag](input: I) = proxy(PolyAll.of[I, E, A], input) | ||
ZLayer( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curly braces instead of parentheses.
docs/ecosystem/officials/zio-mock.md
Outdated
|
||
override def exampleStream(a: Int): stream.Stream[Throwable, String] = | ||
rts.unsafeRun(proxy(ExampleStream, a)) | ||
ZLayer.fromZIO( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ZLayer.apply
here.
docs/ecosystem/officials/zio-mock.md
Outdated
rts.unsafeRun(proxy(ExampleStream, a)) | ||
ZLayer.fromZIO( | ||
ZIO.serviceWithZIO[Proxy] { proxy => | ||
withRuntime[Proxy, ExampleService] { rts => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runtime
instead of rts
.
docs/ecosystem/officials/zio-mock.md
Outdated
proxy(ExampleEffect, i) | ||
|
||
override def exampleMethod(i: Int): String = | ||
Unsafe.unsafe { implicit u => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsafe
instead of u
.
docs/ecosystem/officials/zio-mock.md
Outdated
ZLayer.fromZIO( | ||
ZIO.serviceWithZIO[Proxy] { proxy => | ||
withRuntime[Proxy, ExampleService] { rts => | ||
ZIO.succeed( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curly braces instead of parentheses for multiple line statement.
docs/ecosystem/officials/zio-mock.md
Outdated
ZLayer { | ||
for { | ||
proxy <- ZIO.service[Proxy] | ||
} yield |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can bring up definition of AccountObserver
a line.
docs/ecosystem/officials/zio-mock.md
Outdated
} | ||
}.toLayer | ||
|
||
ZLayer{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space.
docs/ecosystem/officials/zio-mock.md
Outdated
ZLayer{ | ||
for { | ||
proxy <- ZIO.service[mock.Proxy] | ||
} yield |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete extra line.
@JoaquinIglesiasTurina Definitely! Thank you for your work on this! Left detailed comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congratulations on your first contribution to ZIO! 🎉
Updated
zio-mock
documentation as documented on this issue.