1

这可能会成为蹩脚和新手级别的问题之一,但我已经为此苦苦挣扎了一段时间,但仍然无法正常工作。

我有一个 HomeController:

package example

class HomeController {

    def index = { 
        [ message: "Hello, world!" ]
    }
}

现在我已经安装了easyb插件:

grails install-plugin easyb

我还为这个控制器创建了一个基本故事(在“test/unit”文件夹中):

scenario "Should return 'Hello, world!' message", {
    given "Controller is instantiated", {
        mockController HomeController
        controller = new HomeController()
    }

    when "Controller received request for index action"
    and "No additional parameters are expected", {
        result = controller.index()  
    }

    then "Controller displays Hello, world!", {
        result.message.shouldBe "Hello, world!"
    }
}

当我运行 easyb 测试时

grails test-app unit:easyb

而不是这个测试通过,因为它应该我在“当没有其他参数时”收到以下错误消息:

[FAILURE: No signature of method: HomeController.index() is applicable for argument types: () values: []]

然后是第二部分的“然后控制器显示你好,世界!”

[FAILURE: No such property: result for class: HomeController]

我基本上遵循http://grails.org/plugin/easyb的说明。

谁能向我解释我做错了什么?

马蒂亚斯。

4

1 回答 1

0

Oh well, I found it... conventions, conventions, conventions....

Naming the scenario file HomeController.story forced the engine to include "controller" variable in the scope. What's not clear though is why I couldn't do it again...

Nevermind. After removing the "given" part completely it works as it should.

于 2010-10-05T22:02:47.577 回答