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 Jan 13, 2022
1 parent f1565c8 commit ef49fd3
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 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
fqdn = fact('fqdn')

context 'failure before cert' do
# Set up site first, verify things don't work
it 'sets up apache for testing' do
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 ef49fd3

Please sign in to comment.