简体   繁体   English

怎么写在Rspec-rails中记住我的功能?

[英]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. 我使用了巫术宝石来完成登录功能,而且我已经使用了“记住我”的功能。但是我不知道如何用Rspec编写测试代码。我发现了Capybara宝石却不知道如何使用它。
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. 你可以进行2次测试。 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:记得

  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" expect(page).to have_content“你已经登录了”

Test 2: Does not remember 测试2:不记得了

  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" expect(page).to have_content“你必须输入一个名字和密码”

To go to the homepage with Capybara, use visit: 要与Capybara一起访问主页,请访问:

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 这是Capybara参考: https//github.com/teamcapybara/capybara#using-capybara-with-rspec

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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