From ef49fd342e77c57f6b5e2d1ff5a2f81d59a4730f Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Wed, 12 Jan 2022 11:25:01 +0100 Subject: [PATCH] Modernize rspec syntax 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]: https://github.com/rubocop/rubocop-rspec/issues/1231 --- spec/acceptance/certs_spec.rb | 47 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/spec/acceptance/certs_spec.rb b/spec/acceptance/certs_spec.rb index e93c373..3e86a55 100644 --- a/spec/acceptance/certs_spec.rb +++ b/spec/acceptance/certs_spec.rb @@ -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 @@ -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