简体   繁体   English

单元测试问题:参数数目错误(给定0,应为1..2)

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

相关问题 ArgumentError:参数数量错误(给定0,应为1..2) - ArgumentError: wrong number of arguments (given 0, expected 1..2) Rails 中止了! ArgumentError:参数数量错误(给定 0,预期为 1..2) - Rails aborted! ArgumentError: wrong number of arguments (given 0, expected 1..2) Rails 5.1部分中的参数数目错误(给定3,应为1..2) - wrong number of arguments (given 3, expected 1..2) in Rails 5.1 partial Rails:嵌套属性参数内的数组列错误的 arguments 数量(给定 0,预期 1..2) - Rails: array column inside nested attribute params wrong number of arguments (given 0, expected 1..2) 在多个字段上进行回形针验证-参数数量错误(给定3个,期望1..2) - Paperclip validations on multiple fields - wrong number of arguments (given 3, expect 1..2) ActionView :: Template ::错误:参数个数错误(3个为1..2) - ActionView::Template::Error: wrong number of arguments (3 for 1..2) 带导轨4.2.0的参数数量错误(1..2为0) - Wrong number of arguments (0 for 1..2) with rails 4.2.0 参数数目错误(给定0,应为1) - wrong number of arguments (given 0, expected 1) 参数数目错误(给定0,应为4) - wrong number of arguments (given 0, expected 4) 参数数目错误(给定1,预期为0) - wrong number of arguments (given 1, expected 0)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM