[Vuejs]-Rails System Test Not Loading Vue

0👍

Firstly, you’re mixing the use of Capybara with request methods (get, post, etc). You can’t do that since the request methods don’t affect the session Capybara uses (a commit was recently made to rails to undefine the request methods in SystemTestCase because of the confusion they cause – https://github.com/rails/rails/commit/1aea1ddd2a4b3bfa7bb556e4c7cd40f9531ac2e3). To fix this your sign_in method needs to change to actually visit the page, fill in the fields, and submit the form.
Secondly, At the end of sign_in you need to assert for something that would indicate the login has completed. If that isn’t done the visit immediately following the call to sign_in can occur before the cookies get sent back to the browser and you can still end up not signed in.

def sign_in(user)
  visit new_user_session_path # wherever the login page is
  fill_in('user[email]', with: user.email)
  fill_in('user[password], with: user.password)
  click_button('Sign in') # whatever needs to be clicked to login
  assert_text('You are now logged in') # whatever message confirms the login succeeded
end

Leave a comment