Sha256: 1fa9623c97d6e77eb7be0c8cbe6df3462a78b32ed9070971f137f5c2e4d47ae9

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

RSpec.describe ChefVault::Certificate do
  let(:item) { double(ChefVault::Item) }
  let(:cert) { ChefVault::Certificate.new("foo", "bar") }

  before do
    allow(ChefVault::Item).to receive(:load).with("foo", "bar"){ item }
    allow(item).to receive(:[]).with("id"){ "bar" }
    allow(item).to receive(:[]).with("contents"){ "baz" }
    @orig_stdout = $stdout
    $stdout = File.open(File::NULL, 'w')
  end

  after do
    $stdout = @orig_stdout
  end

  describe '#new' do
    it 'loads item' do
      expect(ChefVault::Item).to receive(:load).with("foo", "bar")

      ChefVault::Certificate.new("foo", "bar")
    end
  end

  describe '#[]' do
    specify { expect(cert['id']).to eq 'bar' }
  end

  describe 'decrypt_contents' do
    it 'echoes warning' do
      expect { cert.decrypt_contents }
        .to output("WARNING: This method is deprecated, please switch to item['value'] calls\n")
        .to_stdout
    end

    it 'returns items contents' do
      expect(item).to receive(:[]).with("contents")

      expect(cert.decrypt_contents).to eq 'baz'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chef-vault-2.6.0 spec/chef-vault/certificate_spec.rb