Rspec控制器传递参数

时间:2012-05-18 00:07:01

标签: ruby-on-rails-3 rspec controllers

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

代码

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 ==)

1 个答案:

答案 0 :(得分:8)

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