Cucumber、rails 和会话变量

发布于 2024-11-05 06:31:12 字数 185 浏览 5 评论 0原文

我正在实施两步登录。第一步,用户必须输入他的电子邮件+密码。如果正确,则会生成一个随机字符串,存储在会话中并发送到帐户持有人的移动电话。

我想知道如何从步骤定义中访问会话变量,或者如何以其他方式捕获随机字符串,以便我可以将其填充到表单中,并在用户使用它时测试整个登录。该字符串不存储在模型中,因为它只是临时的。

谢谢, 科林

I'm implementing a two step login. In the first step the user has to enter his email+password. If correct then a random string is generated, stored in the session and sent to the account holder's mobile phone.

I wonder how to access the session variable from within my step definitions or how to otherwise capture the random string so that I can use fill it in the form and so test the whole login as the user would use it. The string is not stored in the model because it's only temporary.

Thanks,
Corin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

阪姬 2024-11-12 06:31:12

存根令牌生成器以返回固定字符串。

Stub the token generator to return a fixed string.

怕倦 2024-11-12 06:31:12

我通过对 SMSGateway 进行存根解决了这个问题。我在 features/env.rb 中的代码:

require 'cucumber/rspec/doubles'

...

Before do |scenario|
  @smsgateway_sent_text_messages = []
  SMSGateway.stub(:send_text_message) do |message, phone_number|
    @smsgateway_sent_text_messages << {
      :phone_number => phone_number,
      :message => message,
    }
  end
end

I solved it by stubbing the SMSGateway. My code in features/env.rb:

require 'cucumber/rspec/doubles'

...

Before do |scenario|
  @smsgateway_sent_text_messages = []
  SMSGateway.stub(:send_text_message) do |message, phone_number|
    @smsgateway_sent_text_messages << {
      :phone_number => phone_number,
      :message => message,
    }
  end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文