0
私はシェフとHashicorp Vaultの
レシピ
chef_gem 'vault' do
compile_time true if Chef::Resource::ChefGem.instance_methods(false).include?(:compile_time)
end
require 'vault'
Vault.address = 'https://address:8200'
Vault.token = citadel['foo/bar']
Vault.auth_token.renew_self
テスト
require_relative '../spec_helper'
describe 'wrapper::default' do
context 'role is foo' do
let(:chef_run) do
ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |node|
node.default['role'] = 'foo'
const_set(:Vault, Module.new)
end.converge(described_recipe)
end
before(:each) do
allow_any_instance_of(Chef::Recipe).to receive(:require).and_call_original
allow_any_instance_of(Chef::Recipe).to receive(:require).with('vault').and_return(true)
allow_any_instance_of(::Vault).to receive(:address).and_call_original
allow_any_instance_of(::Vault).to receive(:address).with('https://localhost:8200').and_return(true)
end
it 'install vault gem' do
expect(chef_run).to install_chef_gem('vault')
end
end
end
エラー
Failure/Error: expect(Chef::Recipe::Vault).to receive(:address).and_call_original
NameError:
uninitialized constant Vault
の実装をテストするためにChefSpecを使用しようとしている
Vault vaをスタブするにはどうすればいいですか?ライバル?これはシェフ・ボールトではなくハシコープ・ボールトです。
私の質問が更新されました。定数を追加してChef :: Recipeを取り出しました。まだ初期化されていない定数が残っています – jsmickey
上記の2番目のビットは 'const_set'または' stub_const'それにスタッフィングすることができます。 – coderanger