[英]unit testing issue: wrong number of arguments (given 0, expected 1..2)
I have an issue with my controller test, when running it in the terminal it return: 我的控制器测试有问题,在终端中运行它时返回:
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>'
my test in stories_controller_test is: 我在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
and in my stories.yml file I have: 在我的stories.yml文件中,我有:
one:
name: Bitcoin Reddit
link: https://www.reddit.com/r/Bitcoin/
If more is necessary please ask and the whole project is here . 如果还有必要,请询问,整个项目在这里 。
Still beginning with unit testing and could not find a solution to this issue. 仍从单元测试开始,找不到针对此问题的解决方案。
I guess what you're trying to use there is assert
, which would eventually fail if the argument isn't true. 我猜您要使用的是
assert
,如果参数不正确,最终会失败。 And as you're trying to check the body, then you must access response.body. 在尝试检查正文时,必须访问response.body。
Edit your test adding the assert and pasing the include? 编辑您的测试,添加断言并粘贴包含项? on response.body asking whether it includes or not the stories(:one).name:
在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.