Skip to content

Commit d06a67b

Browse files
committed
Refactor letsencrypt redis spec
1 parent 59f97b3 commit d06a67b

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

spec/letsencrypt/redis_spec.rb

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
let(:redis) { double(Redis) }
77
let(:domain) { 'example.com' }
88
let(:certificate) do
9-
LetsEncrypt::Certificate.new(domain: domain, key: '', certificate: '')
9+
LetsEncrypt::Certificate.new(domain: domain, key: 'KEY', certificate: 'CERTIFICATE')
1010
end
1111

1212
before(:each) do
@@ -19,28 +19,35 @@
1919
end
2020

2121
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+
2726
LetsEncrypt::Redis.save(certificate)
2827
end
2928

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)) }
3439
end
3540
end
3641

3742
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+
4347
LetsEncrypt::Redis.delete(certificate)
4448
end
49+
50+
it { expect(redis).to have_received(:del).with("#{domain}.key") }
51+
it { expect(redis).to have_received(:del).with("#{domain}.crt") }
4552
end
4653
end

0 commit comments

Comments
 (0)