黄瓜和间隙:当前用户的步骤
我要完成的是在定义 Cucumber 步骤时使用(依赖)current_user
方法。我在我的项目中使用 Clearance。
首先,我尝试使用 sign_in
但它不起作用(我猜 Cucumber World 不知道 Clearance 方法......)。
那么如何让 Cuckes 识别 current_user
和 sign_in
/sign_out
方法呢?
What I what to accomplish is to use (rely on) current_user
method while defining Cucumber steps. I'm using Clearance in my project.
First of all I tried to use sign_in
but it didn't work (I guess Cucumber World doesn't know about Clearance methods...).
So how do I make Cuckes recognize current_user
and sign_in
/sign_out
methods?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不同意每个验收测试(黄瓜或其他)都必须执行登录逻辑的想法。幸运的是,如果您同意,Clearance 添加了一个后门< /a> 在测试中允许您跳过登录步骤。
现在,您可以像用户一样保留与登录相关的功能来驱动登录 ui,并跳过与登录不直接相关的功能。
I disagree with the idea that every acceptance test (cucumber or otherwise) must exercise the login logic. Luckily, if you agree, Clearance has added a back door in tests that lets you skip the sign in steps.
Now you can leave your login-related features driving the login ui as a user would and skip that for features that aren't directly related to logging in.
您的 Cucumber 功能应该通过公共用户界面驱动您的应用程序。类似于:
由于浏览器无法使用
current_user
方法,因此您不应在规范中使用它。您可以通过在上述步骤中存储
@current_user
来伪造它,然后为其提供属性读取器。Your Cucumber features should be driving your application through the public user interface. Something like:
Since the
current_user
method isn't available to the browser, you shouldn't be using it in your spec.You could fake it in your steps by storing
@current_user
in the above step and then providing an attribute reader for it.