Skip to content

Commit

Permalink
Fix last rubocop offenses and fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
smortex committed Aug 5, 2024
1 parent 4b53d77 commit 241a9f4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 59 deletions.
52 changes: 32 additions & 20 deletions spec/classes/augeas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
24 changes: 15 additions & 9 deletions spec/defines/augeas_lens_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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") }
Expand All @@ -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
Expand Down
17 changes: 11 additions & 6 deletions spec/functions/augeas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 0 additions & 24 deletions spec/spec_helper_local.rb

This file was deleted.

0 comments on commit 241a9f4

Please sign in to comment.