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

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

Creates a TestEnvironment as proposed in #1129. Will add more convenience functions and tests once #1252 is merged but wanted to get this out there.

}

object testConsole {
def feedLines(lines: String*): ZIO[TestEnvironment, Nothing, Unit] =
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 fine for this pull request, but in general, I think I'd put these helpers inside the companion objects of the Test* classes.

e.g.:

TestConsole.feedLines(...)

Then there's a logical place for users to look for them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I think this makes sense. One thing I am thinking about is whether it makes sense to have something like:

trait TestConsole extends Console {
  val console: TestConsoleImplementation
}

case class TestConsoleImplementation extends Console.Service[Any]

That way when we define these helper methods we can only depend on the specific environment type that these methods require and users could get the benefit of the method if they only depend on certain mock objects instead of the mock environment. Not sure about naming. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, you are right. Let's follow the ZIO conventions though:

trait MockConsole extends Console {
  val console: MockConsole.Service[Any]
}
object MockConsole {
  trait Service[R] extends Console.Service[R] { def feedLines(...) }

  def feedLines(lines: String*): ZIO[MockConsole, Nothing, Unit] = ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great. I'm on it!


object TestEnvironment {

val Value: Managed[Nothing, TestEnvironment] =
Copy link
Member

Choose a reason for hiding this comment

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

One more organizational tip:

Let's rename TestEnvironment => TestEnvironmentInternals, and make it package private (private[test]).

Then inside zio.test.mock package object, we can do:

package object mock {
  val TestEnvironment: TestEnvironment = TestEnvironmentInternals.Value
}

Then a user has type TestEnvironment and can use value TestEnvironment, which is more Scala-idiomatic.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, actually, I'm not so sure about this, because TestEnvironment.Value has type Managed[...]. So let's leave this the way it is.

We can add this value in package object mock:

val TestEnvironmentManaged: Managed[TestEnvironment] = TestEnvironment.Value

In fact, it probably makes sense to rename TestEnvironment.Value to TestEnvironment.ManagedDefault (a managed, default test environment).

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 on this pull request! It's all coming together nicely.

Just one small change and we can ship it.

@jdegoes
Copy link
Member

jdegoes commented Jul 27, 2019

@adamgfraser Can you do the Mock rename in this PR and merge the conflicts?

@adamgfraser
Copy link
Contributor Author

@jdegoes Yes.

@jdegoes
Copy link
Member

jdegoes commented Jul 27, 2019

Er, mock rename for TestEnvironment, the other ones were taken care of by @dkarlinsky

@adamgfraser
Copy link
Contributor Author

@jdegoes This is ready for another review.

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.

Superb work! These changes add tremendous value to the testkit.

@jdegoes jdegoes merged commit 54b3acf into zio:master Jul 27, 2019
@adamgfraser
Copy link
Contributor Author

@jdegoes Thanks! Means a lot coming from you.

@adamgfraser adamgfraser deleted the 1129 branch July 27, 2019 21:33
@adamgfraser adamgfraser restored the 1129 branch July 27, 2019 21:33
@adamgfraser adamgfraser deleted the 1129 branch July 27, 2019 21:40
ghostdogpr pushed a commit to ghostdogpr/scalaz-zio that referenced this pull request Aug 5, 2019
* create TestEnvironment

* address review comments

* add additional convenience methods

* rename TestEnvironment to MockEnvironment

* refactor to create mock interfaces and services

* add some tests
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.

2 participants