在 Grails 中使用 EasyB
这可能会是蹩脚和新手级别的问题之一,但我已经为此苦苦挣扎了一段时间,但它仍然不起作用。
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哦,好吧,我找到了......约定,约定,约定......
命名场景文件 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.