gpt4 book ai didi

ruby-on-rails - cucumber 速度,性能调整

转载 作者:行者123 更新时间:2023-11-28 20:58:02 25 4
gpt4 key购买 nike

我已经分析了我的特征文件。我发现我的登录步骤花费的时间最多。

Given /^I am logged in as "(.+)"$/ do |login|
visit path_to('the home page')
fill_in "login", :with => login
fill_in "password", :with => 'foobar'
click_button "loginButton"
end

在我的开发箱上花费了 5 多秒。

我想在登录功能上再做一步,但不填写表单,只需设置 session ,并在我的其他测试中将其用作后台场景。

Given /^I am logged in as "(.+)" through session$/ do |login|
user= User.find_by_login(login)
end

上述步骤找到了用户,但我如何才能让它存储 session 并重定向我?

最佳答案

您可以避免在其他步骤中进行身份验证,这可能不是顽固的 cucumber 开发人员会说的。但是,如果您在其他地方测试过身份验证工作流,那么我看不出有什么害处。我没有尝试这个,但我认为变量范围应该是正确的。

Given /^I am logged in as "(.+)" through session$/ do |login|
@user= User.find_by_login(login)
#open the class and spike
class ApplicationController < ActionController::Base
def current_user
@user
end
end
end

关于ruby-on-rails - cucumber 速度,性能调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5102142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com