What other ways are there to test Devise 'not logged in' with Cucumber?

The wiki page for Devise suggests using the following to check if users are logged in:

Given /^I am not authenticated$/ do visit('/users/sign_out') # ensure that at least end 

What works, but it doesn’t feel like it, because it only tests that a certain route is available for visiting and does not verify that the user is not logged in.

Are there other, better ways that can be used to check if a user is logged in using Devise?

+4
source share
1 answer

This statement sets the known state before running the test script, see GWT . In this case, it gives the user a warning before running the script.

You can use the following script to verify that the resource is indeed protected by authentication:

 Scenario: Anonymous denied access Given I am not authenticated When I go to protected_resource Then I should see "You need to sign in or sign up before continuing" 

Protected_resource must be defined in the functions / support / paths.rb

+1
source

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


All Articles