Ruby:有没有办法只模拟已经存在的类方法,但不是全部?

时间:2012-04-29 09:29:17

标签: ruby interface mocking

有没有办法只模拟现有的类方法(具有正确的参数计数),但不是全部?我想测试我使用现有方法和正确的参数计数,即使对象被模拟。

我正在使用ruby 1.9.3和mocha(0.11.1)进行测试。

class A
  def a
    return 1
  end
end

... 

def test_...
  object = A.new # or object = mock( '::A' )
  object.expects( :a ) # ok

  object.expects( :b ) # I want "no method error" to be raised...
  object.stubs( :c ) # And here too
end

1 个答案:

答案 0 :(得分:0)

答案是

Mocha::Configuration.prevent(:stubbing_non_existent_method)

P.S。 http://marklunds.com/articles/one/429

P.P.S。让我自己谷歌:( http://bit.ly/JLrkZQ

相关问题