gpt4 book ai didi

ruby-on-rails - Rspec 测试实例变量与用户创建

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

我正在测试以确保将创建的用户分配给我的实例变量 @user。我明白 get 是什么意思,但我不确定要为测试写什么。我返回错误 URI 或 URL 的参数错误。我的测试有什么问题,我该如何解决?

it "checks @user variable assignment for creation" do

p = FactoryGirl.create(:user)
get :users
# I'm confused on what this line above means/does. What does the hash :users refer
#to
assigns[:user].should == [p]

end

expected URI object or string error 指的是get :users 错误如下

Failure/Error get :users
ArgumentError:
bad argument: (expected URI object or URI string)

最佳答案

我猜你想要的是

it "checks @user variable assignment for creation" do
p = FactoryGirl.create(:user)
get :show, id: p.id
assigns(:user).should == p
end

您不确定的行检查用户 p 的显示 View 中分配的变量 (@user) 的内容是否等于您刚刚创建的 p 用户 more information there

关于ruby-on-rails - Rspec 测试实例变量与用户创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13129583/

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