在 Grails 中使用 EasyB

发布于 2024-09-25 22:00:35 字数 1326 浏览 0 评论 0原文

这可能会是蹩脚和新手级别的问题之一,但我已经为此苦苦挣扎了一段时间,但它仍然不起作用。

我有一个 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: []]

然后对于第二部分在“然后控制器显示Hello,world!”

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

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

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

马蒂亚斯.

It's probably going to be one of the lame and novice level questions but I'm struggling with it for some time and it's still not working.

I have a HomeController:

package example

class HomeController {

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

Now I've installed easyb plugin:

grails install-plugin easyb

I've also created a basic story for this controller (in "test/unit" folder):

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!"
    }
}

When I run the easyb tests

grails test-app unit:easyb

instead of this test passing as it should I get the following error message at "when No additional parameters are expected":

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

and then for the second part at "then Controller displays Hello, world!"

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

I'm basically following the instructions from http://grails.org/plugin/easyb.

Can anyone explain to me what I'm doing wrong?

Matthias.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么这么可爱啊 2024-10-02 22:00:35

哦,好吧,我找到了......约定,约定,约定......

命名场景文件 HomeController.story 强制引擎在范围中包含“controller”变量。但不清楚的是为什么我不能再做一次......

没关系。完全删除“给定”部分后,它就可以正常工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文