gpt4 book ai didi

ruby-on-rails-3 - Rspec Controller 传递参数

转载 作者:行者123 更新时间:2023-12-04 06:59:40 25 4
gpt4 key购买 nike

下面是我遇到的问题。我不确定如何将正确的参数传递给此 Controller 操作。

代码

def get_standards
@standard_children, @temp = Standard.browse(params[:guid])
@parent_standard = params[:guid]
respond_to do |format|
format.js
end
end

Rspec

describe "Get Standards" do
it "should return correct values" do
@stateOne = mock_model(Standard, description: "beta")
Standard.stub!(:browse).and_return(@stateOne, "temp")
assigns(:standard_children).should == @stateOne
assigns(:parent_standard).should == 'one'
get :get_standards, :params => {guid: 'one'}
end
end

错误

 Failure/Error: assigns(:standard_children).should == @stateOne
expected: #<Standard:0x3ffed4e53d88 @name="Standard_1001">
got: nil (using ==)

最佳答案

describe "Get Standards" do
it "should return correct values" do
@stateOne = mock_model(Standard, description: "beta")
Standard.stub!(:browse).and_return(@stateOne, "temp")

get :get_standards, :guid => 'one'
assigns(:parent_standard).should == 'one'
assigns(:standard_children).should == @stateOne
end
end

关于ruby-on-rails-3 - Rspec Controller 传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10645107/

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