Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

Adds "setter" / "update" methods to TestConsole, TestSystem, and TestRandom mock services and hides Ref implementation as proposed in #1240.

@vasilmkd
Copy link
Contributor

Hi @adamgfraser. I'm working on something else, would you be willing to include TestClock as well in this PR? Thanks.

@adamgfraser
Copy link
Contributor Author

adamgfraser commented Jul 26, 2019

@vasilmkd Sure, happy to take it!

@adamgfraser
Copy link
Contributor Author

I updated this to include TestClock.

} yield input
}

def feedLine(line: String): UIO[Unit] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update the signature slightly, for added user-convenience?

def feedLines(lines: String*): UIO[Unit] =

def feedLine(line: String): UIO[Unit] =
ref.update(data => data.copy(input = line :: data.input)).unit

val output: UIO[Vector[String]] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. Probably good to add a clearOutput, too, and maybe clearInput.


def shuffle[A](list: List[A]): UIO[List[A]] = Random.shuffleWith(nextInt, list)

def feedInt(int: Int): UIO[Unit] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto on these, I'd update to feedInts(ints: Int*) for all of them, and add clear methods as well.

def putEnv(name: String, value: String): UIO[Unit] =
ref.update(data => data.copy(envs = data.envs.updated(name, value))).unit

def putProperty(name: String, value: String): UIO[Unit] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, and probably useful to make a clearEnv / clearProperty, as well.

object TestRandom {
val DefaultData: Data = Data()

def apply(data: Data): UIO[TestRandom] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are super handy! I would call them make, though, instead of apply, because they build it inside an effect, rather than return it directly.

import zio.test.mock.TestRandom.Data

final case class TestRandom(ref: Ref[TestRandom.Data]) extends Random.Service[Any] {
final case class TestRandom(private val ref: Ref[TestRandom.Data]) extends Random.Service[Any] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not make this private. Let's just call them, randomState, clockState, systemState, consoleState, etc.

Copy link
Member

@jdegoes jdegoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! A few quick changes and it will be good to merge.

@jdegoes
Copy link
Member

jdegoes commented Jul 26, 2019

@adamgfraser Any interest in taking this one too? 😄

@adamgfraser
Copy link
Contributor Author

@jdegoes Yes I will take it!

@jdegoes
Copy link
Member

jdegoes commented Jul 26, 2019

@adamgfraser Thank you!!! 🙏

@adamgfraser adamgfraser changed the title Add "Setter" / "Update" Methods to Mock Services and Hide Ref Implementation Add "Setter" / "Update" Methods to Mock Services Jul 26, 2019
@adamgfraser
Copy link
Contributor Author

@jdegoes Thanks for your feedback! These should all be addressed now.

@jdegoes
Copy link
Member

jdegoes commented Jul 27, 2019

@adamgfraser Great work, thank you for this!

@jdegoes jdegoes merged commit 1f082de into zio:master Jul 27, 2019
@adamgfraser adamgfraser deleted the 1240 branch July 27, 2019 21:40
ghostdogpr pushed a commit to ghostdogpr/scalaz-zio that referenced this pull request Aug 5, 2019
* Add "setter" / "update" methods to mock services

* include TestClock

* resolve review comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants