现在Rails带有凭证/秘密文件,我似乎无法使用RSpec存根/覆盖秘密。
# credentials.yml.enc
my_token: 111
我们过去常常使用环境变量
allow(ENV).to receive(:[]).with('my_token').and_return('')
所以我期待能够应用相同的逻辑
allow(Rails.application.credentials).to receive(:my_token).and_return('')
但它不会覆盖Rails的秘密。任何的想法?谢谢
应该像这里描述的那样直截了当https://github.com/rspec/rspec-rails/issues/2099#issuecomment-472965256
describe 'Credentials' do
it 'stubs credentials' do
allow(Rails.application.credentials).to receive(:my_token).and_return('123')
expect(Rails.application.credentials.my_token).to eq('123')
end
end