![](/img/trans.png)
[英]ArgumentError: wrong number of arguments (given 0, expected 1..2)
[英]unit testing issue: wrong number of arguments (given 0, expected 1..2)
我的控制器测试有问题,在终端中运行它时返回:
Error:
StoriesControllerTest#test_show_story:
ArgumentError: wrong number of arguments (given 0, expected 1..2)
test/controllers/stories_controller_test.rb:45:in `block in
<class:StoriesControllerTest>'
我在stories_controller_test中的测试是:
test "show story" do
get story_path(stories(:one))
assert_response :success
assert_response.body.include?(stories(:one).name) #line 45
end
在我的stories.yml文件中,我有:
one:
name: Bitcoin Reddit
link: https://www.reddit.com/r/Bitcoin/
如果还有必要,请询问,整个项目在这里 。
仍从单元测试开始,找不到针对此问题的解决方案。
我猜您要使用的是assert
,如果参数不正确,最终会失败。 在尝试检查正文时,必须访问response.body。
编辑您的测试,添加断言并粘贴包含项? 在response.body询问是否包含story(:one).name时:
test "show story" do
get story_path(stories(:one))
assert_response :success
assert response.body.include?(stories(:one).name)
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.