水豚电子邮件重置会话
Capybara email resets the session
我需要在 Capybara 注册后测试智能重定向的特定流程。假设我的网站有几个interesting_pages
,我想在确认注册后将用户重定向到上次访问的有趣页面
小场景:
When I visit the interesting page "42"
And I visit a couple uninteresting pages
# Note during the visit to other pages, session[:interesting_page] is correctly set to the url of page "42"
When I sign up and I confirm via the link in the email
# At this point I have lost the session[:interesting_page]
Then I should be confirmed and redirected to the last visited interesting page "42"
对于实际实施,我决定选择 controller.session[]=
作为 。在呈现 page "42"
的控制器中,我将会话设置为 session[:interesting_page] = request.original_url
在开发中,我在点击电子邮件link中的确认link后,在设计确认期间成功地redirect_to会话[:interesting_page]
然而,当我尝试使用 Cucumber 对此进行测试时,点击电子邮件 link 时,Capybara-email 似乎重置了会话,因此当我点击 link 时 session[:interesting_page]
被删除] 在电子邮件中重新连接...
编辑 When I sign up and I confirm via the link in the email
步骤基本上通过设计注册控制器,我使用 Capybara::Email 单击确认电子邮件
# Nested steps for "When I sign up and I confirm via the link in the email"
I fill in "email" with ...
...
I click "Sign up !"
Then I should see "Please confirm your account via the link !"
# At this stage session[:interesting_page] still exists and points to page "42"
And an email should have been sent to "#{user.email}"
And in the current mail I click "Je finalise mon inscription"
# The RegistrationController code I use is similar to devise and returns a pending_confirmation page
# respond_with resource, location: pending_confirmation_path
# Associated step implementations
Then(/an email should have been sent to "([^"]*)"/) do |address|
open_email(address)
expect(current_email).to be
end
When(/in the current mail I click "([^"]*)"$/) do |link|
current_email.click_link link
end
Capybara 中的动作可以异步发生。这意味着,如果您不检查应该在页面上可见的内容,一旦您执行的任何操作完成,并调用另一个访问或操作,那么由对该操作的响应设置的任何 cookie 可能不会get set,这意味着您实际上并没有登录,也没有保存一些重要数据。在您的情况下,这意味着在(至少)I click "Sign up !"
之后,您需要对成功注册后页面上出现的文本有一个期望。
另一件要检查的事情是电子邮件中 url 的主机名(可能还有端口)是否与您正常访问时使用的主机名相匹配。
我需要在 Capybara 注册后测试智能重定向的特定流程。假设我的网站有几个interesting_pages
,我想在确认注册后将用户重定向到上次访问的有趣页面
小场景:
When I visit the interesting page "42"
And I visit a couple uninteresting pages
# Note during the visit to other pages, session[:interesting_page] is correctly set to the url of page "42"
When I sign up and I confirm via the link in the email
# At this point I have lost the session[:interesting_page]
Then I should be confirmed and redirected to the last visited interesting page "42"
对于实际实施,我决定选择 controller.session[]=
作为 page "42"
的控制器中,我将会话设置为 session[:interesting_page] = request.original_url
在开发中,我在点击电子邮件link中的确认link后,在设计确认期间成功地redirect_to会话[:interesting_page]
然而,当我尝试使用 Cucumber 对此进行测试时,点击电子邮件 link 时,Capybara-email 似乎重置了会话,因此当我点击 link 时 session[:interesting_page]
被删除] 在电子邮件中重新连接...
编辑 When I sign up and I confirm via the link in the email
步骤基本上通过设计注册控制器,我使用 Capybara::Email 单击确认电子邮件
# Nested steps for "When I sign up and I confirm via the link in the email"
I fill in "email" with ...
...
I click "Sign up !"
Then I should see "Please confirm your account via the link !"
# At this stage session[:interesting_page] still exists and points to page "42"
And an email should have been sent to "#{user.email}"
And in the current mail I click "Je finalise mon inscription"
# The RegistrationController code I use is similar to devise and returns a pending_confirmation page
# respond_with resource, location: pending_confirmation_path
# Associated step implementations
Then(/an email should have been sent to "([^"]*)"/) do |address|
open_email(address)
expect(current_email).to be
end
When(/in the current mail I click "([^"]*)"$/) do |link|
current_email.click_link link
end
Capybara 中的动作可以异步发生。这意味着,如果您不检查应该在页面上可见的内容,一旦您执行的任何操作完成,并调用另一个访问或操作,那么由对该操作的响应设置的任何 cookie 可能不会get set,这意味着您实际上并没有登录,也没有保存一些重要数据。在您的情况下,这意味着在(至少)I click "Sign up !"
之后,您需要对成功注册后页面上出现的文本有一个期望。
另一件要检查的事情是电子邮件中 url 的主机名(可能还有端口)是否与您正常访问时使用的主机名相匹配。