Skip to content

Commit

Permalink
Modernize rspec syntax
Browse files Browse the repository at this point in the history
This takes lessons from the rubocop-rspec issue[1] and applies them to
write a more modern style. This should be more compatible with future
versions of rspec.

[1]: rubocop/rubocop-rspec#1231
  • Loading branch information
ekohl committed Aug 27, 2023
1 parent 8f9ccc0 commit cb806de
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions spec/acceptance/certs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

require 'spec_helper_acceptance'

describe 'trusted_ca' do
describe 'trusted_ca', order: :defined do
let(:fqdn) { fact('networking.fqdn') }

context 'failure before cert' do
# Set up site first, verify things don't work
it 'sets up apache for testing' do
Expand All @@ -12,7 +14,7 @@
apache::vhost { 'trusted_ca':
docroot => '/tmp',
port => 443,
servername => $facts['fqdn'],
servername => $facts['networking']['fqdn'],
ssl => true,
ssl_cert => '/etc/ssl-secure/test.crt',
ssl_key => '/etc/ssl-secure/test.key',
Expand All @@ -21,40 +23,37 @@
apply_manifest(pp, catch_failures: true)
end

describe command("/usr/bin/curl https://#{fact('hostname')}.example.com:443") do
its(:exit_status) { is_expected.to eq 60 }
specify do
expect(command("/usr/bin/curl https://#{fqdn}:443")).
to have_attributes(exit_status: 60)
end

describe command("cd /root && /usr/bin/java SSLPoke #{fact('hostname')}.example.com 443") do
its(:exit_status) { is_expected.to eq 1 }
specify do
expect(command("cd /root && /usr/bin/java SSLPoke #{fqdn} 443")).
to have_attributes(exit_status: 1)
end
end

context 'success after cert' do
it 'works idempotently with no errors' do
pp = <<-EOS
class { 'trusted_ca': }
trusted_ca::ca { 'test': source => '/etc/ssl-secure/test.crt' }
EOS

# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'trusted_ca': }
trusted_ca::ca { 'test': source => '/etc/ssl-secure/test.crt' }
PUPPET
end
end

describe package('ca-certificates') do
it { is_expected.to be_installed }
end
specify { expect(package('ca-certificates')).to be_installed }

# https://github.com/rubocop/rubocop-rspec/issues/1231
# rubocop:disable RSpec/RepeatedExampleGroupBody
describe command("/usr/bin/curl https://#{fact('hostname')}.example.com:443") do
its(:exit_status) { is_expected.to eq 0 }
specify do
expect(command("/usr/bin/curl https://#{fqdn}:443")).
to have_attributes(exit_status: 0)
end

describe command("cd /root && /usr/bin/java SSLPoke #{fact('hostname')}.example.com 443") do
its(:exit_status) { is_expected.to eq 0 }
specify do
expect(command("cd /root && /usr/bin/java SSLPoke #{fqdn} 443")).
to have_attributes(exit_status: 0)
end
# rubocop:enable RSpec/RepeatedExampleGroupBody
end
end

0 comments on commit cb806de

Please sign in to comment.