单元测试问题:参数数量错误(给定 0,预期 1..2)
unit testing issue: wrong number of arguments (given 0, expected 1..2)
我的控制器测试有问题,当 运行 它在终端时 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>'
我在 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/
如果需要更多请询问,整个项目是 here。
仍在从单元测试开始,无法找到解决此问题的方法。
我猜你想用的是assert
,
如果参数不正确,最终会失败。当您尝试检查 body 时,您必须访问 response.body.
编辑您的测试添加断言并传递包含?在 response.body 上询问它是否包含 stories(:one).name:
test "show story" do
get story_path(stories(:one))
assert_response :success
assert response.body.include?(stories(:one).name)
end
我的控制器测试有问题,当 运行 它在终端时 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>'
我在 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/
如果需要更多请询问,整个项目是 here。
仍在从单元测试开始,无法找到解决此问题的方法。
我猜你想用的是assert
,
如果参数不正确,最终会失败。当您尝试检查 body 时,您必须访问 response.body.
编辑您的测试添加断言并传递包含?在 response.body 上询问它是否包含 stories(:one).name:
test "show story" do
get story_path(stories(:one))
assert_response :success
assert response.body.include?(stories(:one).name)
end