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

时间:2010-12-27 09:01:06

标签: ruby testing mocha

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

我试过

  1. object.stubs(:everything)
  2. stub_everything('class_name')
  3. 上述两种方式均无效。

1 个答案:

答案 0 :(得分:6)

第二种方法应该有效。请参阅Mocha 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