|
6 | 6 | let(:redis) { double(Redis) }
|
7 | 7 | let(:domain) { 'example.com' }
|
8 | 8 | let(:certificate) do
|
9 |
| - LetsEncrypt::Certificate.new(domain: domain, key: '', certificate: '') |
| 9 | + LetsEncrypt::Certificate.new(domain: domain, key: 'KEY', certificate: 'CERTIFICATE') |
10 | 10 | end
|
11 | 11 |
|
12 | 12 | before(:each) do
|
|
19 | 19 | end
|
20 | 20 |
|
21 | 21 | describe '#save' do
|
22 |
| - it 'saves certificate into redis' do |
23 |
| - certificate.key = 'KEY' |
24 |
| - certificate.certificate = 'CERTIFICATE' |
25 |
| - expect(redis).to receive(:set).with("#{domain}.key", an_instance_of(String)) |
26 |
| - expect(redis).to receive(:set).with("#{domain}.crt", an_instance_of(String)) |
| 22 | + before do |
| 23 | + allow(redis).to receive(:set).with("#{domain}.key", an_instance_of(String)) |
| 24 | + allow(redis).to receive(:set).with("#{domain}.crt", an_instance_of(String)) |
| 25 | + |
27 | 26 | LetsEncrypt::Redis.save(certificate)
|
28 | 27 | end
|
29 | 28 |
|
30 |
| - it 'doesnt save blank certificate into redis' do |
31 |
| - expect(redis).to_not receive(:set).with("#{domain}.key", an_instance_of(String)) |
32 |
| - expect(redis).to_not receive(:set).with("#{domain}.crt", an_instance_of(String)) |
33 |
| - LetsEncrypt::Redis.save(certificate) |
| 29 | + it { expect(redis).to have_received(:set).with("#{domain}.key", 'KEY') } |
| 30 | + it { expect(redis).to have_received(:set).with("#{domain}.crt", 'CERTIFICATE') } |
| 31 | + |
| 32 | + describe 'when key and certificate is empty' do |
| 33 | + let(:certificate) do |
| 34 | + LetsEncrypt::Certificate.new(domain: domain, key: '', certificate: '') |
| 35 | + end |
| 36 | + |
| 37 | + it { expect(redis).not_to have_received(:set).with("#{domain}.key", an_instance_of(String)) } |
| 38 | + it { expect(redis).not_to have_received(:set).with("#{domain}.crt", an_instance_of(String)) } |
34 | 39 | end
|
35 | 40 | end
|
36 | 41 |
|
37 | 42 | describe '#delete' do
|
38 |
| - it 'deletes certificate from redis' do |
39 |
| - certificate.key = 'KEY' |
40 |
| - certificate.certificate = 'CERTIFICATE' |
41 |
| - expect(redis).to receive(:del).with("#{domain}.key") |
42 |
| - expect(redis).to receive(:del).with("#{domain}.crt") |
| 43 | + before do |
| 44 | + allow(redis).to receive(:del).with("#{domain}.key") |
| 45 | + allow(redis).to receive(:del).with("#{domain}.crt") |
| 46 | + |
43 | 47 | LetsEncrypt::Redis.delete(certificate)
|
44 | 48 | end
|
| 49 | + |
| 50 | + it { expect(redis).to have_received(:del).with("#{domain}.key") } |
| 51 | + it { expect(redis).to have_received(:del).with("#{domain}.crt") } |
45 | 52 | end
|
46 | 53 | end
|
0 commit comments