回答
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