3

如何使用 mocha 存根对象上的所有方法?

我试过了

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

以上两种方式都行不通。

4

1 回答 1

6

The second method should work. See the 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
于 2010-12-30T13:37:15.543 回答