diff --git a/spec/classes/augeas_spec.rb b/spec/classes/augeas_spec.rb index 8d7ee07..0c39736 100644 --- a/spec/classes/augeas_spec.rb +++ b/spec/classes/augeas_spec.rb @@ -3,6 +3,14 @@ require 'spec_helper' describe 'augeas' do + let(:lens_dir) do + if (Puppet.version >= '4.0.0') && facts[:rubysitedir] =~ (%r{/opt/puppetlabs/puppet}) + '/opt/puppetlabs/puppet/share/augeas/lenses' + else + '/usr/share/augeas/lenses' + end + end + context 'when on an unsupported Operating System' do let(:facts) do { @@ -16,12 +24,6 @@ end end - lens_dir = if (Puppet.version >= '4.0.0') && facts[:rubysitedir] =~ (%r{/opt/puppetlabs/puppet}) - '/opt/puppetlabs/puppet/share/augeas/lenses' - else - '/usr/share/augeas/lenses' - end - on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do @@ -53,8 +55,10 @@ case facts[:lsbdistcodename] when 'squeeze', 'lucid', 'precise' let(:facts) do - super().merge(ruby: { version: '1.8.7' }) - super().merge(rubyversion: '1.8.7') + facts.merge({ + ruby: { version: '1.8.7' }, + rubyversion: '1.8.7' + }) end it { @@ -65,8 +69,10 @@ } else let(:facts) do - super().merge(ruby: { version: '1.9.3' }) - super().merge(rubyversion: '1.9.3') + facts.merge({ + ruby: { version: '1.9.3' }, + rubyversion: '1.9.3' + }) end it { @@ -155,8 +161,10 @@ case facts[:lsbdistcodename] when 'squeeze', 'lucid', 'precise' let(:facts) do - super().merge(ruby: { version: '1.8.7' }) - super().merge(rubyversion: '1.8.7') + facts.merge({ + ruby: { version: '1.8.7' }, + rubyversion: '1.8.7' + }) end it { @@ -167,8 +175,10 @@ } else let(:facts) do - super().merge(ruby: { version: '1.9.3' }) - super().merge(rubyversion: '1.9.3') + facts.merge({ + ruby: { version: '1.9.3' }, + rubyversion: '1.9.3' + }) end it { @@ -239,12 +249,14 @@ facts.merge(is_pe: true) end - pe_lens_dir = if Puppet::Util::Package.versioncmp(Puppet.version, '4.0.0') >= 0 - # the enterprise lens dir is the same in 4 - lens_dir - else - '/opt/puppet/share/augeas/lenses' - end + let(:pe_lens_dir) do + if Puppet::Util::Package.versioncmp(Puppet.version, '4.0.0') >= 0 + # the enterprise lens dir is the same in 4 + lens_dir + else + '/opt/puppet/share/augeas/lenses' + end + end it { is_expected.to contain_file(pe_lens_dir).with( diff --git a/spec/defines/augeas_lens_spec.rb b/spec/defines/augeas_lens_spec.rb index 76e4d0c..c40de02 100644 --- a/spec/defines/augeas_lens_spec.rb +++ b/spec/defines/augeas_lens_spec.rb @@ -5,11 +5,13 @@ describe 'augeas::lens' do let(:title) { 'foo' } - lens_dir = if (Puppet.version >= '4.0.0') && facts[:rubysitedir] =~ (%r{/opt/puppetlabs/puppet}) - '/opt/puppetlabs/puppet/share/augeas/lenses' - else - '/usr/share/augeas/lenses' - end + let(:lens_dir) do + if (Puppet.version >= '4.0.0') && facts[:rubysitedir] =~ (%r{/opt/puppetlabs/puppet}) + '/opt/puppetlabs/puppet/share/augeas/lenses' + else + '/usr/share/augeas/lenses' + end + end context 'when declaring augeas class first' do on_supported_os.each do |os, facts| @@ -62,8 +64,10 @@ end let(:facts) do - super().merge(augeas: { version: '1.0.0' }) - super().merge(augeasversion: '1.0.0') + facts.merge({ + augeas: { version: '1.0.0' }, + augeasversion: '1.0.0' + }) end it { is_expected.to contain_file("#{lens_dir}/foo.aug") } @@ -79,8 +83,10 @@ end let(:facts) do - super().merge(augeas: { version: '1.3.0' }) - super().merge(augeasversion: '1.3.0') + facts.merge({ + augeas: { version: '1.3.0' }, + augeasversion: '1.3.0' + }) end it do diff --git a/spec/functions/augeas_spec.rb b/spec/functions/augeas_spec.rb index e1c6609..537fda5 100644 --- a/spec/functions/augeas_spec.rb +++ b/spec/functions/augeas_spec.rb @@ -8,13 +8,14 @@ it { is_expected.not_to be_nil } it 'fails if the augeas feature is not present' do - Puppet.features.expects(:augeas?).returns(false) + allow(Puppet.features).to receive(:augeas?).and_return(false) is_expected.to run.with_params('', 'Foo.lns', []).and_raise_error(Puppet::ParseError, %r{requires the augeas feature}) + expect(Puppet.features).to have_received(:augeas?) end context 'when passing wrong arguments' do before do - Puppet.features.stubs(:augeas?).returns(true) + allow(Puppet.features).to receive(:augeas?).and_return(true) end it 'raises a ParseError if there are no arguments' do @@ -69,15 +70,19 @@ context 'when using old libs' do it 'does not work with Augeas prior to 1.0.0' do - expect(Augeas).to receive(:open).and_return(aug) - expect(aug).to receive(:get).with('/augeas/version').and_return('0.10.0') + allow(Augeas).to receive(:open).and_return(aug) + allow(aug).to receive(:get).with('/augeas/version').and_return('0.10.0') is_expected.to run.with_params("\n", 'Fstab.lns', []).and_raise_error(Puppet::ParseError, %r{requires Augeas 1\.0\.0}) + expect(Augeas).to have_received(:open) + expect(aug).to have_received(:get).with('/augeas/version') end it 'does not work with ruby-augeas prior to 0.5.0' do - expect(Augeas).to receive(:open).and_return(aug) - expect(aug).to receive(:methods).and_return([]) + allow(Augeas).to receive(:open).and_return(aug) + allow(aug).to receive(:methods).and_return([]) is_expected.to run.with_params("\n", 'Fstab.lns', []).and_raise_error(Puppet::ParseError, %r{requires ruby-augeas 0\.5\.0}) + expect(Augeas).to have_received(:open) + expect(aug).to have_received(:methods) end end end diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb deleted file mode 100644 index 2afb76f..0000000 --- a/spec/spec_helper_local.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -# HACK: to enable all the expect syntax (like allow_any_instance_of) in rspec-puppet examples -RSpec::Mocks::Syntax.enable_expect(RSpec::Puppet::ManifestMatchers) - -RSpec.configure do |config| - config.mock_with :rspec - - config.before do - # Ensure that we don't accidentally cache facts and environment between - # test cases. This requires each example group to explicitly load the - # facts being exercised with something like - # Facter.collection.loader.load(:ipaddress) - Facter.clear - Facter.clear_messages - - RSpec::Mocks.setup - end - - config.after do - RSpec::Mocks.verify - RSpec::Mocks.teardown - end -end