Skip to content

Commit

Permalink
Refactor letsencrypt spec
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Nov 8, 2023
1 parent 4731d98 commit e54f17e
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions spec/letsencrypt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:tempfile) { Tempfile.new }
let(:key) { OpenSSL::PKey::RSA.new(2048) }

before :each do
before do
LetsEncrypt.class_eval do
@private_key = nil
@endpoint = nil
Expand All @@ -16,38 +16,37 @@
end

describe '#generate_private_key' do
it 'create a new private key' do
key = LetsEncrypt.generate_private_key
expect(LetsEncrypt.private_key.to_s).to eq(key.to_s)
end
let!(:key) { LetsEncrypt.generate_private_key }

it { expect(LetsEncrypt.private_key.to_s).to eq(key.to_s) }
end

describe '#register' do
let(:acme_client) { double(Acme::Client) }
let(:acme_account) { double }

it 'register new account to Let\'s Encrypt' do
before do
tempfile.write(key.to_s)
tempfile.rewind

allow(LetsEncrypt).to receive(:client).and_return(acme_client)
allow(acme_client).to receive(:new_account).and_return(acme_account)
allow(acme_account).to receive(:kid).and_return('')

LetsEncrypt.register('[email protected]')
end

it { expect(LetsEncrypt.register('[email protected]')).to be_truthy }
end

describe 'certificate_model' do
before do
stub_const('OtherModel', Class.new(LetsEncrypt::Certificate))

LetsEncrypt.config.certificate_model = 'OtherModel'

allow(LetsEncrypt).to receive(:certificate_model) { LetsEncrypt.config.certificate_model.constantize }
end

after { LetsEncrypt.config.certificate_model = 'LetsEncrypt::Certificate' }
it 'set the certificate_model to customize model' do
expect(LetsEncrypt.certificate_model).to eq('OtherModel'.constantize)
end

it { expect(LetsEncrypt).to have_attributes(certificate_model: OtherModel) }
end
end

0 comments on commit e54f17e

Please sign in to comment.