0
在我的控制器中,我有一個方法來檢查下一個項目。但是在執行這個方法之前,我需要設置一個寫在before_filter方法中的實例變量。那麼如何在rspec中測試它。在過濾器rspec之前檢查實例變量值
before_filter method check_items, :only[:next]
def check_items
if params[:item] == "Sherlock"
@item = $book1
elsif params[:item] == "Harry"
@queue = $book2
else
render :json=>{"Error" => "Book name does not exist"}
end
end
=======================
def next
@book = @item.pull
unless @book.nil?
respond_with(@book)
else
render :json =>{"msg"=>"Nothing to pull"}
end
end
你解決了這個問題嗎?如果是這樣,你可以與我們分享知識嗎?..你嘗試了建議的答案嗎? –