黄瓜和间隙:当前用户的步骤

发布于 2024-10-03 08:00:24 字数 272 浏览 6 评论 0原文

我要完成的是在定义 Cucumber 步骤时使用(依赖)current_user 方法。我在我的项目中使用 Clearance。

首先,我尝试使用 sign_in 但它不起作用(我猜 Cucumber World 不知道 Clearance 方法......)。

那么如何让 Cuckes 识别 current_usersign_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 技术交流群。

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

发布评论

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

评论(2

卷耳 2024-10-10 08:00:25

我不同意每个验收测试(黄瓜或其他)都必须执行登录逻辑的想法。幸运的是,如果您同意,Clearance 添加了一个后门< /a> 在测试中允许您跳过登录步骤。

user = create(:user)
visit posts_path(as: user)

现在,您可以像用户一样保留与登录相关的功能来驱动登录 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.

user = create(:user)
visit posts_path(as: user)

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.

把梦留给海 2024-10-10 08:00:24

您的 Cucumber 功能应该通过公共用户界面驱动您的应用程序。类似于:

Given /^I am signed in as "([^\"]*)"%/ do |username|
  visit 'sign_in'
  fill_in 'Username', :with => username
  click 'Sign In'
end

由于浏览器无法使用 current_user 方法,因此您不应在规范中使用它。

您可以通过在上述步骤中存储 @current_user 来伪造它,然后为其提供属性读取器。

Your Cucumber features should be driving your application through the public user interface. Something like:

Given /^I am signed in as "([^\"]*)"%/ do |username|
  visit 'sign_in'
  fill_in 'Username', :with => username
  click 'Sign In'
end

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文