Redirect to example.com when trying to log in with Capybara, Cucumber, RSpec and Devise

Trying to get a very simple script using Cucumber and Devise - Signing in user ... (EPIC FAIL)

I have a step like this:

user = create(user_sym) user.confirm! visit new_user_session_path fill_in 'Email',:with => user.email fill_in 'Password',:with => attributes_for(user_sym)[:password] click_button 'Sign in' page.should have_content('Sign out') 

The logs show me that everything is fine (confirm sending the email, UPDATE inserts the correct confirmation flags) and then I see the redirect to

 www.example.com 

Many posts here and elsewhere mention this and use login_user with: callback => false to make it work, but I want to use a "visit".

What could be the reason for this. The actual error is a failed TEST, i.e. The output text is not displayed. What is displayed is Rails Homepage ie

  expected there to be text "Sign out" in "Browse the documentation Rails Guides Rails API Ruby core Ruby standard library Welcome aboard 

I can't figure out what part of the stack throws this (since I'm NEW!). Presumably Capybara redirects? I have seen people make this work, and in my Dev stack, it is explicitly redirected to the Users index page, as you would expect.

Any light is greatly appreciated.

+4
source share
1 answer

I fixed this by returning a specific path in after_sign_in_path_for to ApplicationController

  def after_sign_in_path_for(resource) xxxxx_path end 

Somehow the root route in the cucumber tests is redirected to "example.com"

+1
source

Source: https://habr.com/ru/post/1484402/


All Articles