如何使用mocha对对象的所有内容进行存根

ush*_*sha 3 ruby testing mocha.js

如何使用mocha删除对象上的所有方法?

我试过了

  1. object.stubs(:everything)
  2. stub_everything('class_name')

以上两种方式均无效.

dom*_*esz 6

第二种方法应该有效.参见摩卡Api

def test_product
  product = stub_everything('ipod_product', :price => 100)
  assert_nil product.manufacturer
  assert_nil product.any_old_method
  assert_equal 100, product.price
end
Run Code Online (Sandbox Code Playgroud)