Grails 3.0 生成的 ControllerSpec

Grails 3.0 generated ControllerSpec

仍然是 Grails 新手,非常享受学习和解决问题的过程,但有时看起来非常简单的东西会让我感到困惑。

Grails 生成的 ControllerSpec 类 包括一些合理的测试,其中大部分都很简单,但是有没有人可以给我解释一下这个测试中的一些 syntax/logic:

    void "Test the index action returns the correct model"() {

    when:"The index action is executed"
        controller.index()

    then:"The model is correct"
        !model.fooBarList
        model.fooBarCount == 0
}

特别是下面一行:

!model.fooBarList

逻辑对我来说似乎是错误的,调用 controller.index() 将填充 model.fooBarList 那么为什么断言它不存在?

完全期待这里的 doh 时刻,但我需要帮助才能到达那里!

The logic seems wrong to me, calling controller.index() will populate model.fooBarList so why assert that it doesn't exist?

并不是真的断言fooBarList不存在。 model.fooBarList 应该是一个空列表,它也将通过该测试。