使用 open_id_authentication 插件时,如何在 RSpec 用户故事/Cucumber 中伪造 OpenID 登录
我正在尝试编写一个 Cucumber 场景,要求我有一个登录用户 - 这通常非常简单,但我只使用 OpenID 身份验证(身份验证插件的curtosy)。 然而,在深入研究 open_id_authentication 插件之后,我不确定如何在 Cucumber 中实现这一目标。
I'm trying to write a Cucumber scenario that requires me to have a logged in user - that would normally be quite simple but I'm only using OpenID authentication (curtosy of the authentication plugin). However after digging through the open_id_authentication plugins guts I'm not sure how I could achieve this within Cucumber.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我已经找到了一种方法,如果你将其放在 features/support/env.rb 中:
那么你可以在适当的步骤中执行类似的操作:
我只是完全破坏了黄瓜功能的开放 ID 身份验证,显然,如果我需要登录失败的实例,我可以根据提供的identity_url 来做到这一点。
I've figured out a way, if you place this in your features/support/env.rb:
Then you can just do something like this in your appropriate step:
I'm just completely clobbering the open id auth for the cucumber features, obviously if I need instances where there is failed login I could do that based on the supplied identity_url.
如果您希望能够存根响应,请执行以下操作:
在 features/support/helpers.rb 中:
通过将响应移至单独的方法,您现在可以在必要时在步骤中存根响应。 例如,如果我想要一个 :missing 响应,并且我有一个控制器 GoogleLoginController,我可以使用 Mocha 执行以下操作:
If you want to be able to stub out responses do this:
In features/support/helpers.rb:
By moving the response out to a separate method you can now stub the response in your steps if necessary. For example, if I wanted a :missing response and I had a controller GoogleLoginController I could do the following using Mocha:
Bort,一个rails骨架应用,有全套的rspec测试,支持openID登录,所以你可以想看看他们做了什么。
Bort, a rails skeleton app, has a full set of rspec tests and supports openID login so you may want to take a look and see what they do.
DEfusion 的答案是有效的,只是我需要将 Identity_url 规范化,例如:
谢谢
DEfusion's answer works except that I needed to normalize the identity_url like:
Thanks