quii / learn-go-with-tests

Learn Go with test-driven development
MIT License
22.26k stars 2.82k forks source link

Failed test at Mocking tutorial #808

Open TheInvincibleRalph opened 3 months ago

TheInvincibleRalph commented 3 months ago

The implemetation here:

func Countdown(out io.Writer, sleeper Sleeper) {
    for i := countdownStart; i > 0; i-- {
        sleeper.Sleep()
    }

    for i := countdownStart; i > 0; i-- {
        fmt.Fprintln(out, i)
    }

    fmt.Fprint(out, finalWord)
}

gives this error:

--- FAIL: TestCountdown (0.00s)
    --- FAIL: TestCountdown/sleep_before_every_print (0.00s)
        c:\Testing\mocking\mocking_test.go:60: wanted calls [write sleep write sleep write sleep write] got [sleep sleep sleep write write write write]
FAIL
quii commented 3 months ago

I'm not sure exactly where you are, so it's very hard for me to offer any help, but these tests do pass.

Maybe have a look here https://github.com/quii/learn-go-with-tests/tree/main/mocking/v5

TheInvincibleRalph commented 3 months ago

The function was refactored in the main file you sent:

func Countdown(out io.Writer, sleeper Sleeper) {

    for i := countdownStart; i > 0; i-- {
        fmt.Fprintln(out, i)
        sleeper.Sleep()
    }

    fmt.Fprint(out, finalWord)
}

but the change was not later made in the tutorial here: https://github.com/quii/learn-go-with-tests/blob/main/mocking.md