Skip to content

Commit

Permalink
replace stubs with rspec syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
zilchms committed Apr 3, 2024
1 parent 56f87c3 commit e5f2289
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 107 deletions.
58 changes: 29 additions & 29 deletions spec/unit/puppet/provider/rsyslog_filter/augeas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
let(:target) { tmptarget.path }

it 'creates new entry with file' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

apply!(Puppet::Type.type(:rsyslog_filter).new(
name: 'my test',
Expand All @@ -36,10 +36,10 @@
end

it 'creates new entry with protocol/hostname/port' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

apply!(Puppet::Type.type(:rsyslog_filter).new(
name: 'my test',
Expand Down Expand Up @@ -68,12 +68,12 @@
let(:target) { tmptarget.path }

it 'lists instances' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

provider_class.stubs(:target).returns(target)
allow(provider_class).to receive(:target).and_return(target)
inst = provider_class.instances.map do |p|
{
name: p.get(:name),
Expand Down Expand Up @@ -104,10 +104,10 @@

describe 'when creating settings' do
it 'creates a simple new entry' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

apply!(Puppet::Type.type(:rsyslog_filter).new(
name: 'my test',
Expand All @@ -129,10 +129,10 @@

describe 'when modifying settings' do
it 'uses file' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

apply!(Puppet::Type.type(:rsyslog_filter).new(
name: 'ssh',
Expand All @@ -154,10 +154,10 @@

describe 'when removing settings' do
it 'removes the entry' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

apply!(Puppet::Type.type(:rsyslog_filter).new(
name: 'ssh',
Expand All @@ -183,10 +183,10 @@
let(:target) { tmptarget.path }

it 'fails to load' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

txn = apply(Puppet::Type.type(:rsyslog_filter).new(
name: 'ssh',
Expand Down
82 changes: 41 additions & 41 deletions spec/unit/puppet/provider/syslog/augeas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
let(:target) { tmptarget.path }

it 'creates simple new entry' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

apply!(Puppet::Type.type(:syslog).new(
name: 'my test',
Expand All @@ -35,10 +35,10 @@
end

it 'creates hostname entry with tcp protocol' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

if protocol_supported
apply!(Puppet::Type.type(:syslog).new(
Expand Down Expand Up @@ -77,10 +77,10 @@
end

it 'creates hostname entry with udp protocol' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

if protocol_supported == :stock
apply!(Puppet::Type.type(:syslog).new(
Expand Down Expand Up @@ -137,10 +137,10 @@
end

it 'creates hostname entry with port' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

if protocol_supported # port requires protocol
apply!(Puppet::Type.type(:syslog).new(
Expand Down Expand Up @@ -186,12 +186,12 @@
let(:target) { tmptarget.path }

it 'lists instances' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

provider_class.stubs(:target).returns(target)
allow(provider_class).to receive(:target).and_return(target)
inst = provider_class.instances.map do |p|
{
name: p.get(:name),
Expand All @@ -216,10 +216,10 @@

describe 'when creating settings' do
it 'creates a simple new entry' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

apply!(Puppet::Type.type(:syslog).new(
name: 'my test',
Expand All @@ -241,10 +241,10 @@

describe 'when modifying settings' do
it 'adds a no_sync flag' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

apply!(Puppet::Type.type(:syslog).new(
name: 'cron.*',
Expand All @@ -264,10 +264,10 @@
end

it 'removes the no_sync flag' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

apply!(Puppet::Type.type(:syslog).new(
name: 'mail.*',
Expand All @@ -289,10 +289,10 @@

describe 'when removing settings' do
it 'removes the entry' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

apply!(Puppet::Type.type(:syslog).new(
name: 'mail.*',
Expand All @@ -317,10 +317,10 @@
let(:target) { tmptarget.path }

it 'fails to load' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/syslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

txn = apply(Puppet::Type.type(:syslog).new(
name: 'mail.*',
Expand Down
74 changes: 37 additions & 37 deletions spec/unit/puppet/provider/syslog/rsyslog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def valid_lens?
let(:target) { tmptarget.path }

it 'creates simple new entry' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

apply!(Puppet::Type.type(:syslog).new(
name: 'my test',
Expand All @@ -40,10 +40,10 @@ def valid_lens?
end

it 'creates hostname entry with tcp protocol' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

if protocol_supported
apply!(Puppet::Type.type(:syslog).new(
Expand Down Expand Up @@ -82,10 +82,10 @@ def valid_lens?
end

it 'creates hostname entry with udp protocol' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

if protocol_supported == :stock
apply!(Puppet::Type.type(:syslog).new(
Expand Down Expand Up @@ -142,10 +142,10 @@ def valid_lens?
end

it 'creates hostname entry with port' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

if protocol_supported # port requires protocol
apply!(Puppet::Type.type(:syslog).new(
Expand Down Expand Up @@ -191,12 +191,12 @@ def valid_lens?
let(:target) { tmptarget.path }

it 'lists instances' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

provider_class.stubs(:target).returns(target)
allow(provider_class).to receive(:target).and_return(target)
inst = provider_class.instances.map do |p|
{
name: p.get(:name),
Expand Down Expand Up @@ -241,10 +241,10 @@ def valid_lens?

describe 'when modifying settings' do
it 'adds a no_sync flag' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

apply!(Puppet::Type.type(:syslog).new(
name: 'cron.*',
Expand All @@ -264,10 +264,10 @@ def valid_lens?
end

it 'removes the no_sync flag' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

apply!(Puppet::Type.type(:syslog).new(
name: 'mail.*',
Expand All @@ -289,10 +289,10 @@ def valid_lens?

describe 'when removing settings' do
it 'removes the entry' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

apply!(Puppet::Type.type(:syslog).new(
name: 'mail.*',
Expand All @@ -317,10 +317,10 @@ def valid_lens?
let(:target) { tmptarget.path }

it 'fails to load' do
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
FileTest.stubs(:exist?).returns false
FileTest.stubs(:exist?).with('/etc/rsyslog.conf').returns true
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)
allow(FileTest).to receive(:exist?).and_return(false)
allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true)

txn = apply(Puppet::Type.type(:syslog).new(
name: 'mail.*',
Expand Down

0 comments on commit e5f2289

Please sign in to comment.