How can I use Cucumber to test Devise Rememberable functionality?

I would like the Cucumber function to test the catchy devise functionality (remember what I bought).

It's easy to check the Remember Me checkbox with capybara, but how can I simulate a user returning to the site after closing my window?

+7
ruby-on-rails devise cucumber
source share
5 answers

I came up with the following hack rack and a slightly cleaner selenium api to test Devise remember-me functionality in cucumber / capybara. It simply tells the driver to manually delete the session cookie. Not all drivers are supported, I used only the two that I used:

http://gist.github.com/484787

This involves storing session cookies. Remove the @announce tag from the script to get rid of the verbosity.

Another option suggested by Matt Wynne in discussing the mailing list is to browse other cookie stores and delete them on request or delete the file:

removed from a book with flexible rails:

config.action_controller.session_store = CGI::Session::PStore (or just :p_store) config.action_controller.session_options[:tmpdir] = "/Users/dave/tmp" config.action_controller.session_options[:prefix] = "myapp_session_" 

or

 rake db:sessions:create config.action_controller.session_store = :active_record_store 

Rails also has a reset session method, but I believe that we do not have access to this, because we cannot connect to the rails session when testing with capybara.

Hope this helps,

Nick

+1
source share

nruth gist was really useful, but I felt that deleting a cookie by name was a hoax. I created a step that deletes cookies that the browser will delete when it is closed and restarted (any cookie without an expiration date, set and set in the future).

You can see this in this commit (although I did it only for the RackTest driver, since I don't have Selenium settings), you can also see my login / remember_me function in this commit . And I reorganized the classes for separating files in this commit .

Hope this is helpful.

+1
source share

I used email-spec to accomplish this. My scenario is as follows:

 @allow-rescue Scenario: Create New Account (Everything cool) Given I am not authenticated When I go to register And I fill in "Name" with "bill" And I fill in "Email" with "bill@example.com" And I fill in "Password" with "please" And I fill in "Password Confirmation" with "please" And I press "Sign up" Then "bill@example.com" should receive an email And I open the email And I should see "Confirm my account" in the email body When I follow "Confirm my account" in the email Then I should see "Your account was successfully confirmed. You are now signed in." 

Note the @ allow-rescue decoration above the script, which is required when using Devise.

Hope this helps.

0
source share

I assume you can exit with capybara and then re-enter something like

 Given I am on the login screen And I select 'Remember Me' And I click 'login' Then I should be 'logged in' When I click 'log out' Then I should be 'logged out' #=> potentially destroy a session here? When I click log in Then I should be logged in And I should not be directed to the login form. 

To model this stream, the current state of the cabybara cookie should be used.

0
source share

You can use show_me_the_cookies for this, as shown below:

 And(/^I leave the site$/) do expire_cookies end 
0
source share

All Articles