How to mock/stub the config initializer hash in rails 3

对着背影说爱祢 提交于 2019-12-06 00:53:36

The method that is being called when you do AppConfig['foo'] is the [] method, which takes one argument (the key to retrieve)

Therefore what you could do in your test is

AppConfig.stub(:[]).and_return('1..11')

You can use with to setup different expectations based on the value of the argument, ie

AppConfig.stub(:[]).with('foo').and_return('1..11')
AppConfig.stub(:[]).with('bar').and_return(3)

You don't need to setup a mock AppConfig object - you can stick your stub straight on the 'real' one.

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