开发者

How to mock Rails::configuration

I'm attempting to test a class whic开发者_开发问答h makes use of the rails configuration file. I'd like to mock Rails::configuration.

I've tried things like

Rails::singleton_class.expects(:configuration).returns('result')
Rails::singleton_class.stubs(:configuration).returns('result')

How do I go about doing this?


Rails.expects(:configuration).returns('result')

Please note there was a typo in your example. The returned value must be passed using returns, not return.

Also note, Rails.configuration returns Rails.application.config. If your method doesn't use Rails.configuration directly, it might actually bypass the call and your expectation won't work.


Rails.stubs(:configuration).returns(Rails::Application::Configuration.allocate)

This answer on mocking a Net response helped

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜