简体   繁体   中英

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:

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:

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. And as you're trying to check the body, then you must access 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:

test "show story" do
  get story_path(stories(:one))
  assert_response :success
  assert response.body.include?(stories(:one).name)
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM