3

How to stub out all the methods on an object using mocha ?

I tried

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

Both of the above ways are not working.

Vega
  • 27,856
  • 27
  • 95
  • 103
usha
  • 31
  • 1
  • 2
  • As @dombesz says, version 2 should work. Can you explain why you think it isn't working? Perhaps you expect it to work differently? – James Mead Jan 05 '11 at 02:47
  • 1
    I believe he is trying to do what I want to do, i.e. something to the effect of `RestClient.expect.any_method.never` instead of having to write `RestClient.expect(:get).never; RestClient.expect(:post).never; RestClient.expect(:put).never; RestClient.expect(:delete).never`. There doesn't seem to be a way. – einarmagnus Jan 10 '12 at 09:05

1 Answers1

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
dombesz
  • 7,890
  • 5
  • 38
  • 47