'Stub a call to Rails.application.config_for with Rspec?

I have a method with the following line:

permissions = Rails.application.config_for(:admin_auth)

It reads the file config/admin_auth.yml and returns a Hash that I use later in the the same method.

The problem is that in order to test this method I need to give different values to permissions but I can not find the way to stub the Rails.application.config_for call.

I tried:

allow(Rails::Application).to receive(:config_for) { { admin: 'super_admin' } }

But I get an error.



Solution 1:[1]

Try:

allow_any_instance_of(Rails::Applcation).to ...

or

allow(Rails.application).to ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mori