0
我試圖運行這樣的測試:從控制器Rspec的控制器測試失敗
it "render form to update an bundle with a specific id" do
bundle = mock_model(Bundle)
Bundle.stub!(:find).with("1") { bundle }
get :edit, :locale => "en", :id => 1
Bundle.should_receive(:find).with("1").and_return(bundle)
end
代碼:
class BundlesController < ApplicationController
# GET /bundles
# GET /bundles.json
.....
# GET /bundles/1/edit
def edit
@bundle = Bundle.find(params[:id])
end
.....
end
但測試失敗消息:
BundlesController捆綁更新的形式呈現使用特定ID更新捆綁軟件 失敗/錯誤:Bundle.should_receive(:find).with(「1」)。and_return(bundle) ().find(「1」) 預期:1周時間 好評:0次 #./spec/controllers/bundles_controller_spec.rb:60:in`塊(3級)的「
誰能幫助我? 謝謝!
我們沒有證據表明控制器實際上有一個編輯操作,或者編輯操作調用了'Bundle.find'。請給我們更多的代碼。 –
我的猜測是:用一個字符串'「1」代替整數'1':':id =>「1」'。 – rdvdijk