开发者

How to mock Rails::configuration

开发者 https://www.devze.com 2023-04-01 05:51 出处:网络
I\'m attempting to test a class whic开发者_开发问答h makes use of the rails configuration file.I\'d like 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

精彩评论

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