Rails Tutorial - Ch. 8 - ArgumentError in RSpec tests with 'before' line
-
12-11-2019 - |
Вопрос
I'm following the Rails Tutorial by Michael Hartl and I'm getting an unexpected error/failed test in section 8.2.6 Signing Out - http://ruby.railstutorial.org/chapters/sign-in-sign-out?version=3.2#sec:signing_out
The code I used for my RSpec tests that is failing can be found in listing 8.28. The following code:
before { click_link "Sign out", method: :delete }
is giving the following error:
ArgumentError: wrong number of arguments (2 for 1)
# (eval):2:in 'click_link'
# ./spec/requests/authentication_pages_spec.rb:35:in 'block (5 levels) in <top (required)>
I confirmed that my code is exactly as is shown in the example in Hartl's tutorial, but I'm still getting a failing test. Thoughts?
Решение
The capybara method click_link
only takes a single parameter, which is the name of the link you want to activate. So I think the code should really only be:
before { click_link "Sign Out" }
The rest of the code you had looks like the end of the sign_out action in thew view:
<%= link_to "Sign out", signout_path, method: => :delete %>
By using Capybara to click the link, it should already be utilizing the above code inside the view, so the last junk seems like duplication.
I would just remove the "method: :delete" and see what you get.