[英]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.