开发者

cucumber, rails and session variables

开发者 https://www.devze.com 2023-03-01 22:49 出处:网络
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开发者_开发技

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


Stub the token generator to return a fixed string.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消