回答
rspec-mock代碼表明您可以調用unstub
方法。我引述:
# Removes a stub. On a double, the object will no longer respond to
# `message`. On a real object, the original method (if it exists) is
# restored.
#
# This is rarely used, but can be useful when a stub is set up during a
# shared `before` hook for the common case, but you want to replace it
# for a special case.
def unstub(message)
::RSpec::Mocks.space.proxy_for(self).remove_stub(message)
end
隨着新expect
語法,unstub
已被棄用。你可以這樣做:
# stub
allow(SomeClass).to receive(:a_method)
# do something...
# unstub
allow(SomeClass).to receive(:a_method).and_call_original
如果第一allow
包含.with
或塊,我相信它還是會進行到下一個呼叫,所以接下來allow
並不清楚這些事情。
謝謝你。你有沒有參考這個文檔或代碼中的位置? – steel 2014-09-12 17:56:49
這應該被標記爲導軌4的正確答案rspec 3.0 – 2014-11-11 20:49:14
版本Rspec 3的文檔。https://relishapp.com/rspec/rspec-mocks/docs/configuring-responses/calling-the-original-implementation – counterbeing 2015-08-26 22:34:32
- 1. 有沒有辦法強制RSpec顯示中間結果?
- 2. 有沒有辦法用rspec檢查內部方法變量?
- 3. 有沒有辦法在NetBeans
- 4. 有沒有辦法在Notepad ++
- 5. 有沒有辦法在UIWebview
- 6. 有沒有辦法爲RSpec HTTP存根使用級聯規則?
- 7. 有沒有辦法在cuBLAS中做「saypx」?
- 8. 有沒有辦法在VBA中連接?
- 9. 有沒有辦法說∃!在序言中?
- 10. 有沒有辦法在python中重載+ =?
- 11. 有沒有辦法「svn unrevert」?
- 12. 有沒有辦法-preload- UICollectionViewCell?
- 13. 有沒有辦法寫unity3d
- 14. 有沒有辦法收集?
- 15. 有沒有辦法從APP
- 16. 有沒有辦法appendTo頭?
- 17. 有沒有辦法在MySQL中沒有鎖定?
- 18. RSpec:有沒有辦法在任何級別檢查嵌套的散列鍵?
- 19. 有沒有辦法在XBL中創建私有方法?
- 20. 有沒有辦法讓元素在GTM
- 21. 有沒有辦法在XML資源
- 22. 有沒有辦法在一個數組
- 23. 有沒有辦法在junit ant
- 24. 有沒有辦法在Vim的
- 25. 有沒有辦法在Test :: Unit
- 26. 有沒有辦法在prepareForSegue被稱爲
- 27. 有沒有辦法在一個數組
- 28. 有沒有辦法在代碼
- 29. 有沒有辦法讓Vis.js Network居中?
- 30. 在C#中沒有辦法等待嗎?
你能解釋一下你爲什麼要取消某些東西嗎?也許有更好的方法。 – 2013-04-26 22:43:18