gpt4 book ai didi

ruby-on-rails - rails : How can I ignore fixtures for single test

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

我有两个测试。每个的结果取决于用户数量。

目前,我没有用户固定装置。第二个测试在其设置方法中引入了一个用户。如果数据库中有用户,第一个测试将失败。

但是我想在users.yml中引入用户。因此,第一个测试将因现有用户而失败。有什么方法可以指示此测试忽略 fixtures/users.yml

require 'test_helper'

class UsersSignupTestWithoutExistingUsers < ActionDispatch::IntegrationTest
test "Signup page is accessible" do
get new_user_registration_path
assert_response :success
end
end

class UsersSignupTestWithExistingUsers < ActionDispatch::IntegrationTest
def setup
post user_registration_path, params: {user: {
email: "user@test.com",
password: "password",
password_confirmation: "password"
}}
end

test "Signup page will redirect" do
get new_user_registration_path
assert_response :redirect
end
end

最佳答案

在不需要数据库中任何用户的测试中,您可以 stub 在数据库中查找用户的方法,以便它为该测试返回一个空集。

关于ruby-on-rails - rails : How can I ignore fixtures for single test,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47360813/

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