Last active
June 4, 2020 11:42
-
-
Save dariathecracker/d31b9685639ff080d355be7a69f2f45d to your computer and use it in GitHub Desktop.
Mock implementation of service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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