diff --git a/spec/letsencrypt_spec.rb b/spec/letsencrypt_spec.rb index a4d288a..c32ad7f 100644 --- a/spec/letsencrypt_spec.rb +++ b/spec/letsencrypt_spec.rb @@ -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 @@ -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('example@example.com') end + + it { expect(LetsEncrypt.register('example@example.com')).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