gpt4 book ai didi

ruby-on-rails - 使用 Cucumber,有没有办法让用户在没有界面的情况下登录?

转载 作者:行者123 更新时间:2023-12-01 03:59:14 24 4
gpt4 key购买 nike

我的绝大多数 Cucumber 功能都需要用户登录。但是我真的不需要为每个测试都测试登录功能。我目前正在使用 Devise 进行身份验证。

我正在寻找一种无需填写登录表单即可使用 devise 登录用户的方法。有没有办法做到这一点?我宁愿不必在每次测试中都使用登录操作。

最佳答案

不,没有办法。在 documentation ,关于 sign_in @usersign_out @user辅助方法,它说:

These helpers are not going to work for integration tests driven by Capybara or Webrat. They are meant to be used with functional tests only. Instead, fill in the form or explicitly set the user in session


正如您自己所说,使用 before :each 可能是最干净的。堵塞。我喜欢像下面这样构建它:
context "login necessary" do
# Before block
before do
visit new_user_session_path
fill_in "Email", with: "test@test.com"
fill_in "Password", with: "password"
click_button "Login"
assert_contain "You logged in successfully."
end

# Actual tests that require the user to be logged in
it "does everything correctly" do
# ...
end
end

context "login not necessary" do
it "does stuff" do
# code
end
end

我发现这非常有用,因为如果我更改身份验证规则(即用户是否必须为特定路径登录),我可以进行整个测试并将其移动到另一个描述块中,而无需更改任何更多代码。

关于ruby-on-rails - 使用 Cucumber,有没有办法让用户在没有界面的情况下登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14634330/

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