stub an instance variable using mocha

亡梦爱人 提交于 2019-12-13 03:38:30

问题


Let's say I have a method that references an instance variable directly:

class MyClass
  def method1
    puts @instance_var
  end
end

How can I stub out the value of @instance_var using mocha in a Test::Unit test?


回答1:


You can't. That's one of the many reasons why you should never access ivars directly.



来源:https://stackoverflow.com/questions/9971192/stub-an-instance-variable-using-mocha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!