Skip to content

Instantly share code, notes, and snippets.

@dariathecracker
Last active June 4, 2020 11:42
Show Gist options
  • Save dariathecracker/d31b9685639ff080d355be7a69f2f45d to your computer and use it in GitHub Desktop.
Save dariathecracker/d31b9685639ff080d355be7a69f2f45d to your computer and use it in GitHub Desktop.
Mock implementation of service
package ioleo.tictactoe.cli
import zio.Managed
import zio.test.{assertM, checkM, suite, testM, DefaultRunnableSpec, Gen}
import zio.test.Assertion.equalTo
import zio.test.mock.Expectation.value
import zio.test.mock.MockConsole
import TerminalSpecUtils._
object TerminalSpec extends DefaultRunnableSpec(
suite("Terminal")(
suite("getUserInput")(
testM("delegates to Console") {
checkM(Gen.anyString) { input =>
val app = Terminal.>.getUserInput
val mock = MockConsole.getStrLn returns value(input)
val env = makeEnv(mock)
val result = app.provideManaged(env)
assertM(result, equalTo(input))
}
}
)
)
)
object TerminalSpecUtils {
def makeEnv(consoleEnv: Managed[Nothing, MockConsole]): Managed[Nothing, TerminalLive] =
consoleEnv.map(c => new TerminalLive {
val console = c.console
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment