简体   繁体   中英

how to write remember me feature in Rspec-rails?

I use the sorcery gem to complete the login feature,and I have used the "remember me" feature.But I don't know how to write the test code with Rspec.I found the Capybara gem but don't know how to use it.
what I want to test is when I check the remember me box to login,and then logout with the admin username and password what I login last time,if not there is no any value.
can anybody give me some hint?thank you very much.

You could have 2 tests. I don't know exactly how your site works (or how remember me function works), so here is the basic idea.

Test 1: Remembers

  1. Visit home page
  2. Check "remember me"
  3. Fill out form
  4. Click login
  5. Click logout
  6. Visit home page
  7. Click login
  8. expect(page).to have_content "You have logged in"

Test 2: Does not remember

  1. Visit home page
  2. Fill out form
  3. Click login
  4. Click logout
  5. Visit home page
  6. Click login
  7. expect(page).to have_content "You must enter a name and password"

To go to the homepage with Capybara, use visit:

visit '/'

To check a box:

check 'remember_me'

You'll need to fill out the form and click on buttons.

Here is the Capybara reference: https://github.com/teamcapybara/capybara#using-capybara-with-rspec

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM