aboutsummaryrefslogtreecommitdiff
path: root/spec/unit/provider/cron
diff options
context:
space:
mode:
authorJorie Tappa <jorie@jorietappa.com>2018-07-31 17:01:34 -0500
committerJorie Tappa <jorie@jorietappa.com>2018-08-01 10:30:53 -0500
commit90216d84f8a2da1f77107dc5f0e3d76a3d72aacc (patch)
tree6c8b98d86ed8ea12c20a6e4234b595d99c922ad4 /spec/unit/provider/cron
parenta2af7dd0b9713f279724d2c7e6f17bfd8ce2d95b (diff)
downloadpuppet-cron_core-90216d84f8a2da1f77107dc5f0e3d76a3d72aacc.tar.gz
puppet-cron_core-90216d84f8a2da1f77107dc5f0e3d76a3d72aacc.tar.bz2
Apply automatic pdk validate fixes
Diffstat (limited to 'spec/unit/provider/cron')
-rw-r--r--spec/unit/provider/cron/crontab_spec.rb107
-rw-r--r--spec/unit/provider/cron/parsed_spec.rb349
2 files changed, 221 insertions, 235 deletions
diff --git a/spec/unit/provider/cron/crontab_spec.rb b/spec/unit/provider/cron/crontab_spec.rb
index 98ae589..92924ae 100644
--- a/spec/unit/provider/cron/crontab_spec.rb
+++ b/spec/unit/provider/cron/crontab_spec.rb
@@ -10,17 +10,17 @@ describe Puppet::Type.type(:cron).provider(:crontab) do
def compare_crontab_text(have, want)
# We should have four header lines, and then the text...
- expect(have.lines.to_a[0..3]).to be_all {|x| x =~ /^# / }
+ expect(have.lines.to_a[0..3]).to be_all { |x| x =~ %r{^# } }
expect(have.lines.to_a[4..-1].join('')).to eq(want)
end
- context "with the simple samples" do
+ context 'with the simple samples' do
FIELDS = {
- :crontab => %w{command minute hour month monthday weekday}.collect { |o| o.intern },
- :environment => [:line],
- :blank => [:line],
- :comment => [:line],
- }
+ crontab: ['command', 'minute', 'hour', 'month', 'monthday', 'weekday'].map { |o| o.to_sym },
+ environment: [:line],
+ blank: [:line],
+ comment: [:line],
+ }.freeze
def compare_crontab_record(have, want)
want.each do |param, value|
@@ -48,52 +48,51 @@ describe Puppet::Type.type(:cron).provider(:crontab) do
end
records = []
- text = ""
+ text = ''
# Sorting is from the original, and avoids :empty being the last line,
# since the provider will ignore that and cause this to fail.
- samples.sort_by {|x| x.first.to_s }.each do |name, data|
+ samples.sort_by { |x| x.first.to_s }.each do |_name, data|
records << data[:record]
text << data[:text] + "\n"
end
- it "should parse all sample records at once" do
+ it 'parses all sample records at once' do
subject.parse(text).zip(records).each do |round|
compare_crontab_record(*round)
end
end
- it "should reconstitute the file from the records" do
+ it 'reconstitutes the file from the records' do
compare_crontab_text subject.to_file(records), text
end
- context "multi-line crontabs" do
- tests = { :simple => [:spaces_in_command_with_times],
- :with_name => [:name, :spaces_in_command_with_times],
- :with_env => [:environment, :spaces_in_command_with_times],
- :with_multiple_envs => [:environment, :lowercase_environment, :spaces_in_command_with_times],
- :with_name_and_env => [:name_with_spaces, :another_env, :spaces_in_command_with_times],
- :with_name_and_multiple_envs => [:long_name, :another_env, :fourth_env, :spaces_in_command_with_times]
- }
+ context 'multi-line crontabs' do
+ tests = { simple: [:spaces_in_command_with_times],
+ with_name: [:name, :spaces_in_command_with_times],
+ with_env: [:environment, :spaces_in_command_with_times],
+ with_multiple_envs: [:environment, :lowercase_environment, :spaces_in_command_with_times],
+ with_name_and_env: [:name_with_spaces, :another_env, :spaces_in_command_with_times],
+ with_name_and_multiple_envs: [:long_name, :another_env, :fourth_env, :spaces_in_command_with_times] }
all_records = []
all_text = ''
tests.each do |name, content|
- data = content.map {|x| samples[x] or raise "missing sample data #{x}" }
- text = data.map {|x| x[:text] }.join("\n") + "\n"
- records = data.map {|x| x[:record] }
+ data = content.map { |x| samples[x] || raise("missing sample data #{x}") }
+ text = data.map { |x| x[:text] }.join("\n") + "\n"
+ records = data.map { |x| x[:record] }
# Capture the whole thing for later, too...
all_records += records
all_text += text
- context name.to_s.gsub('_', ' ') do
- it "should regenerate the text from the record" do
+ context name.to_s.tr('_', ' ') do
+ it 'regenerates the text from the record' do
compare_crontab_text subject.to_file(records), text
end
- it "should parse the records from the text" do
+ it 'parses the records from the text' do
subject.parse(text).zip(records).each do |round|
compare_crontab_record(*round)
end
@@ -101,30 +100,30 @@ describe Puppet::Type.type(:cron).provider(:crontab) do
end
end
- it "should parse the whole set of records from the text" do
+ it 'parses the whole set of records from the text' do
subject.parse(all_text).zip(all_records).each do |round|
compare_crontab_record(*round)
end
end
- it "should regenerate the whole text from the set of all records" do
+ it 'regenerates the whole text from the set of all records' do
compare_crontab_text subject.to_file(all_records), all_text
end
end
end
- context "when receiving a vixie cron header from the cron interface" do
- it "should not write that header back to disk" do
+ context 'when receiving a vixie cron header from the cron interface' do
+ it 'does not write that header back to disk' do
vixie_header = File.read(my_fixture('vixie_header.txt'))
vixie_records = subject.parse(vixie_header)
- compare_crontab_text subject.to_file(vixie_records), ""
+ compare_crontab_text subject.to_file(vixie_records), ''
end
end
- context "when adding a cronjob with the same command as an existing job" do
- let(:record) { {:name => "existing", :user => "root", :command => "/bin/true", :record_type => :crontab} }
- let(:resource) { Puppet::Type::Cron.new(:name => "test", :user => "root", :command => "/bin/true") }
- let(:resources) { { "test" => resource } }
+ context 'when adding a cronjob with the same command as an existing job' do
+ let(:record) { { name: 'existing', user: 'root', command: '/bin/true', record_type: :crontab } }
+ let(:resource) { Puppet::Type::Cron.new(name: 'test', user: 'root', command: '/bin/true') }
+ let(:resources) { { 'test' => resource } }
before :each do
subject.stubs(:prefetch_all_targets).returns([record])
@@ -142,64 +141,64 @@ describe Puppet::Type.type(:cron).provider(:crontab) do
# subject.to_file(subject.records).should match /Puppet name: test/
# end
- it "should not base the new resource's provider on the existing record" do
+ it "does not base the new resource's provider on the existing record" do
subject.expects(:new).with(record).never
subject.stubs(:new)
subject.prefetch(resources)
end
end
- context "when prefetching an entry now managed for another user" do
+ context 'when prefetching an entry now managed for another user' do
let(:resource) do
- s = stub(:resource)
- s.stubs(:[]).with(:user).returns 'root'
- s.stubs(:[]).with(:target).returns 'root'
- s
+ s = stub(:resource)
+ s.stubs(:[]).with(:user).returns 'root'
+ s.stubs(:[]).with(:target).returns 'root'
+ s
end
- let(:record) { {:name => "test", :user => "nobody", :command => "/bin/true", :record_type => :crontab} }
- let(:resources) { { "test" => resource } }
+ let(:record) { { name: 'test', user: 'nobody', command: '/bin/true', record_type: :crontab } }
+ let(:resources) { { 'test' => resource } }
before :each do
subject.stubs(:prefetch_all_targets).returns([record])
end
- it "should try and use the match method to find a more fitting record" do
+ it 'tries and use the match method to find a more fitting record' do
subject.expects(:match).with(record, resources)
subject.prefetch(resources)
end
- it "should not match a provider to the resource" do
+ it 'does not match a provider to the resource' do
resource.expects(:provider=).never
subject.prefetch(resources)
end
- it "should not find the resource when looking up the on-disk record" do
+ it 'does not find the resource when looking up the on-disk record' do
subject.prefetch(resources)
expect(subject.resource_for_record(record, resources)).to be_nil
end
end
- context "when matching resources to existing crontab entries" do
- let(:first_resource) { Puppet::Type::Cron.new(:name => :one, :user => 'root', :command => '/bin/true') }
- let(:second_resource) { Puppet::Type::Cron.new(:name => :two, :user => 'nobody', :command => '/bin/false') }
+ context 'when matching resources to existing crontab entries' do
+ let(:first_resource) { Puppet::Type::Cron.new(name: :one, user: 'root', command: '/bin/true') }
+ let(:second_resource) { Puppet::Type::Cron.new(name: :two, user: 'nobody', command: '/bin/false') }
- let(:resources) {{:one => first_resource, :two => second_resource}}
+ let(:resources) { { one: first_resource, two: second_resource } }
- describe "with a record with a matching name and mismatching user (#2251)" do
+ describe 'with a record with a matching name and mismatching user (#2251)' do
# Puppet::Resource objects have #should defined on them, so in these
# examples we have to use the monkey patched `must` alias for the rspec
# `should` method.
it "doesn't match the record to the resource" do
- record = {:name => :one, :user => 'notroot', :record_type => :crontab}
+ record = { name: :one, user: 'notroot', record_type: :crontab }
expect(subject.resource_for_record(record, resources)).to be_nil
end
end
- describe "with a record with a matching name and matching user" do
- it "matches the record to the resource" do
- record = {:name => :two, :target => 'nobody', :command => '/bin/false'}
+ describe 'with a record with a matching name and matching user' do
+ it 'matches the record to the resource' do
+ record = { name: :two, target: 'nobody', command: '/bin/false' }
expect(subject.resource_for_record(record, resources)).to eq(second_resource)
end
end
diff --git a/spec/unit/provider/cron/parsed_spec.rb b/spec/unit/provider/cron/parsed_spec.rb
index 6cec867..6d5b752 100644
--- a/spec/unit/provider/cron/parsed_spec.rb
+++ b/spec/unit/provider/cron/parsed_spec.rb
@@ -3,79 +3,78 @@
require 'spec_helper'
describe Puppet::Type.type(:cron).provider(:crontab) do
-
let :provider do
- described_class.new(:command => '/bin/true')
+ described_class.new(command: '/bin/true')
end
let :resource do
Puppet::Type.type(:cron).new(
- :minute => %w{0 15 30 45},
- :hour => %w{8-18 20-22},
- :monthday => %w{31},
- :month => %w{12},
- :weekday => %w{7},
- :name => 'basic',
- :command => '/bin/true',
- :target => 'root',
- :provider => provider
+ minute: ['0', '15', '30', '45'],
+ hour: ['8-18', '20-22'],
+ monthday: ['31'],
+ month: ['12'],
+ weekday: ['7'],
+ name: 'basic',
+ command: '/bin/true',
+ target: 'root',
+ provider: provider,
)
end
let :resource_special do
Puppet::Type.type(:cron).new(
- :special => 'reboot',
- :name => 'special',
- :command => '/bin/true',
- :target => 'nobody'
+ special: 'reboot',
+ name: 'special',
+ command: '/bin/true',
+ target: 'nobody',
)
end
let :resource_sparse do
Puppet::Type.type(:cron).new(
- :minute => %w{42},
- :target => 'root',
- :name => 'sparse'
+ minute: ['42'],
+ target: 'root',
+ name: 'sparse',
)
end
let :record_special do
{
- :record_type => :crontab,
- :special => 'reboot',
- :command => '/bin/true',
- :on_disk => true,
- :target => 'nobody'
+ record_type: :crontab,
+ special: 'reboot',
+ command: '/bin/true',
+ on_disk: true,
+ target: 'nobody',
}
end
let :record do
{
- :record_type => :crontab,
- :minute => %w{0 15 30 45},
- :hour => %w{8-18 20-22},
- :monthday => %w{31},
- :month => %w{12},
- :weekday => %w{7},
- :special => :absent,
- :command => '/bin/true',
- :on_disk => true,
- :target => 'root'
+ record_type: :crontab,
+ minute: ['0', '15', '30', '45'],
+ hour: ['8-18', '20-22'],
+ monthday: ['31'],
+ month: ['12'],
+ weekday: ['7'],
+ special: :absent,
+ command: '/bin/true',
+ on_disk: true,
+ target: 'root',
}
end
- describe "when determining the correct filetype" do
- it "should use the suntab filetype on Solaris" do
+ describe 'when determining the correct filetype' do
+ it 'uses the suntab filetype on Solaris' do
Facter.stubs(:value).with(:osfamily).returns 'Solaris'
expect(described_class.filetype).to eq(Puppet::Util::FileType::FileTypeSuntab)
end
- it "should use the aixtab filetype on AIX" do
+ it 'uses the aixtab filetype on AIX' do
Facter.stubs(:value).with(:osfamily).returns 'AIX'
expect(described_class.filetype).to eq(Puppet::Util::FileType::FileTypeAixtab)
end
- it "should use the crontab filetype on other platforms" do
+ it 'uses the crontab filetype on other platforms' do
Facter.stubs(:value).with(:osfamily).returns 'Not a real operating system family'
expect(described_class.filetype).to eq(Puppet::Util::FileType::FileTypeCrontab)
end
@@ -83,155 +82,144 @@ describe Puppet::Type.type(:cron).provider(:crontab) do
# I'd use ENV.expects(:[]).with('USER') but this does not work because
# ENV["USER"] is evaluated at load time.
- describe "when determining the default target" do
- it "should use the current user #{ENV['USER']}", :if => ENV['USER'] do
+ describe 'when determining the default target' do
+ it "should use the current user #{ENV['USER']}", if: ENV['USER'] do
expect(described_class.default_target).to eq(ENV['USER'])
end
- it "should fallback to root", :unless => ENV['USER'] do
- expect(described_class.default_target).to eq("root")
+ it 'fallbacks to root', unless: ENV['USER'] do
+ expect(described_class.default_target).to eq('root')
end
end
- describe ".targets" do
- let(:tabs) { [ described_class.default_target ] + %w{foo bar} }
- before do
+ describe '.targets' do
+ let(:tabs) { [described_class.default_target] + ['foo', 'bar'] }
+
+ before(:each) do
File.expects(:readable?).returns true
File.stubs(:file?).returns true
File.stubs(:writable?).returns true
end
- after do
+ after(:each) do
File.unstub :readable?, :file?, :writable?
Dir.unstub :foreach
end
- it "should add all crontabs as targets" do
+ it 'adds all crontabs as targets' do
Dir.expects(:foreach).multiple_yields(*tabs)
expect(described_class.targets).to eq(tabs)
end
end
- describe "when parsing a record" do
- it "should parse a comment" do
- expect(described_class.parse_line("# This is a test")).to eq({
- :record_type => :comment,
- :line => "# This is a test",
- })
+ describe 'when parsing a record' do
+ it 'parses a comment' do
+ expect(described_class.parse_line('# This is a test')).to eq(record_type: :comment,
+ line: '# This is a test')
end
- it "should get the resource name of a PUPPET NAME comment" do
- expect(described_class.parse_line('# Puppet Name: My Fancy Cronjob')).to eq({
- :record_type => :comment,
- :name => 'My Fancy Cronjob',
- :line => '# Puppet Name: My Fancy Cronjob',
- })
+ it 'gets the resource name of a PUPPET NAME comment' do
+ expect(described_class.parse_line('# Puppet Name: My Fancy Cronjob')).to eq(record_type: :comment,
+ name: 'My Fancy Cronjob',
+ line: '# Puppet Name: My Fancy Cronjob')
end
- it "should ignore blank lines" do
- expect(described_class.parse_line('')).to eq({:record_type => :blank, :line => ''})
- expect(described_class.parse_line(' ')).to eq({:record_type => :blank, :line => ' '})
- expect(described_class.parse_line("\t")).to eq({:record_type => :blank, :line => "\t"})
- expect(described_class.parse_line(" \t ")).to eq({:record_type => :blank, :line => " \t "})
+ it 'ignores blank lines' do
+ expect(described_class.parse_line('')).to eq(record_type: :blank, line: '')
+ expect(described_class.parse_line(' ')).to eq(record_type: :blank, line: ' ')
+ expect(described_class.parse_line("\t")).to eq(record_type: :blank, line: "\t")
+ expect(described_class.parse_line(" \t ")).to eq(record_type: :blank, line: " \t ")
end
- it "should extract environment assignments" do
+ it 'extracts environment assignments' do
# man 5 crontab: MAILTO="" with no value can be used to surpress sending
# mails at all
- expect(described_class.parse_line('MAILTO=""')).to eq({:record_type => :environment, :line => 'MAILTO=""'})
- expect(described_class.parse_line('FOO=BAR')).to eq({:record_type => :environment, :line => 'FOO=BAR'})
- expect(described_class.parse_line('FOO_BAR=BAR')).to eq({:record_type => :environment, :line => 'FOO_BAR=BAR'})
- expect(described_class.parse_line('SPACE = BAR')).to eq({:record_type => :environment, :line => 'SPACE = BAR'})
+ expect(described_class.parse_line('MAILTO=""')).to eq(record_type: :environment, line: 'MAILTO=""')
+ expect(described_class.parse_line('FOO=BAR')).to eq(record_type: :environment, line: 'FOO=BAR')
+ expect(described_class.parse_line('FOO_BAR=BAR')).to eq(record_type: :environment, line: 'FOO_BAR=BAR')
+ expect(described_class.parse_line('SPACE = BAR')).to eq(record_type: :environment, line: 'SPACE = BAR')
end
- it "should extract a cron entry" do
- expect(described_class.parse_line('* * * * * /bin/true')).to eq({
- :record_type => :crontab,
- :hour => :absent,
- :minute => :absent,
- :month => :absent,
- :weekday => :absent,
- :monthday => :absent,
- :special => :absent,
- :command => '/bin/true'
- })
- expect(described_class.parse_line('0,15,30,45 8-18,20-22 31 12 7 /bin/true')).to eq({
- :record_type => :crontab,
- :minute => %w{0 15 30 45},
- :hour => %w{8-18 20-22},
- :monthday => %w{31},
- :month => %w{12},
- :weekday => %w{7},
- :special => :absent,
- :command => '/bin/true'
- })
+ it 'extracts a cron entry' do
+ expect(described_class.parse_line('* * * * * /bin/true')).to eq(record_type: :crontab,
+ hour: :absent,
+ minute: :absent,
+ month: :absent,
+ weekday: :absent,
+ monthday: :absent,
+ special: :absent,
+ command: '/bin/true')
+ expect(described_class.parse_line('0,15,30,45 8-18,20-22 31 12 7 /bin/true')).to eq(record_type: :crontab,
+ minute: ['0', '15', '30', '45'],
+ hour: ['8-18', '20-22'],
+ monthday: ['31'],
+ month: ['12'],
+ weekday: ['7'],
+ special: :absent,
+ command: '/bin/true')
# A percent sign will cause the rest of the string to be passed as
# standard input and will also act as a newline character. Not sure
# if puppet should convert % to a \n as the command property so the
# test covers the current behaviour: Do not do any conversions
- expect(described_class.parse_line('0 22 * * 1-5 mail -s "It\'s 10pm" joe%Joe,%%Where are your kids?%')).to eq({
- :record_type => :crontab,
- :minute => %w{0},
- :hour => %w{22},
- :monthday => :absent,
- :month => :absent,
- :weekday => %w{1-5},
- :special => :absent,
- :command => 'mail -s "It\'s 10pm" joe%Joe,%%Where are your kids?%'
- })
+ expect(described_class.parse_line('0 22 * * 1-5 mail -s "It\'s 10pm" joe%Joe,%%Where are your kids?%')).to eq(record_type: :crontab,
+ minute: ['0'],
+ hour: ['22'],
+ monthday: :absent,
+ month: :absent,
+ weekday: ['1-5'],
+ special: :absent,
+ command: 'mail -s "It\'s 10pm" joe%Joe,%%Where are your kids?%')
end
- describe "it should support special strings" do
- ['reboot','yearly','anually','monthly', 'weekly', 'daily', 'midnight', 'hourly'].each do |special|
+ describe 'it should support special strings' do
+ ['reboot', 'yearly', 'anually', 'monthly', 'weekly', 'daily', 'midnight', 'hourly'].each do |special|
it "should support @#{special}" do
- expect(described_class.parse_line("@#{special} /bin/true")).to eq({
- :record_type => :crontab,
- :hour => :absent,
- :minute => :absent,
- :month => :absent,
- :weekday => :absent,
- :monthday => :absent,
- :special => special,
- :command => '/bin/true'
- })
+ expect(described_class.parse_line("@#{special} /bin/true")).to eq(record_type: :crontab,
+ hour: :absent,
+ minute: :absent,
+ month: :absent,
+ weekday: :absent,
+ monthday: :absent,
+ special: special,
+ command: '/bin/true')
end
end
end
end
- describe ".instances" do
+ describe '.instances' do
before :each do
described_class.stubs(:default_target).returns 'foobar'
end
- describe "on linux" do
- before do
+ describe 'on linux' do
+ before(:each) do
Facter.stubs(:value).with(:osfamily).returns 'Linux'
Facter.stubs(:value).with(:operatingsystem)
end
- it "should contain no resources for a user who has no crontab" do
+ it 'contains no resources for a user who has no crontab' do
# `crontab...` does only capture stdout here. On vixie-cron-4.1
# STDERR shows "no crontab for foobar" but stderr is ignored as
# well as the exitcode.
- described_class.target_object('foobar').expects(:`).with('crontab -u foobar -l 2>/dev/null').returns ""
- expect(described_class.instances.select { |resource|
+ described_class.target_object('foobar').expects(:`).with('crontab -u foobar -l 2>/dev/null').returns ''
+ expect(described_class.instances.select do |resource|
resource.get('target') == 'foobar'
- }).to be_empty
+ end).to be_empty
end
- it "should contain no resources for a user who is absent" do
+ it 'contains no resources for a user who is absent' do
# `crontab...` does only capture stdout. On vixie-cron-4.1
# STDERR shows "crontab: user `foobar' unknown" but stderr is
# ignored as well as the exitcode
- described_class.target_object('foobar').expects(:`).with('crontab -u foobar -l 2>/dev/null').returns ""
- expect(described_class.instances.select { |resource|
+ described_class.target_object('foobar').expects(:`).with('crontab -u foobar -l 2>/dev/null').returns ''
+ expect(described_class.instances.select do |resource|
resource.get('target') == 'foobar'
- }).to be_empty
+ end).to be_empty
end
- it "should be able to create records from not-managed records" do
+ it 'is able to create records from not-managed records' do
described_class.stubs(:target_object).returns File.new(my_fixture('simple'))
parameters = described_class.instances.map do |p|
- h = {:name => p.get(:name)}
+ h = { name: p.get(:name) }
Puppet::Type.type(:cron).validproperties.each do |property|
h[property] = p.get(property)
end
@@ -264,95 +252,94 @@ describe Puppet::Type.type(:cron).provider(:crontab) do
expect(parameters[1][:target]).to eq('foobar')
end
- it "should be able to parse puppet managed cronjobs" do
+ it 'is able to parse puppet managed cronjobs' do
described_class.stubs(:target_object).returns File.new(my_fixture('managed'))
expect(described_class.instances.map do |p|
- h = {:name => p.get(:name)}
+ h = { name: p.get(:name) }
Puppet::Type.type(:cron).validproperties.each do |property|
h[property] = p.get(property)
end
h
end).to eq([
- {
- :name => 'real_job',
- :minute => :absent,
- :hour => :absent,
- :weekday => :absent,
- :month => :absent,
- :monthday => :absent,
- :special => :absent,
- :command => '/bin/true',
- :ensure => :present,
- :environment => :absent,
- :user => :absent,
- :target => 'foobar'
- },
- {
- :name => 'complex_job',
- :minute => :absent,
- :hour => :absent,
- :weekday => :absent,
- :month => :absent,
- :monthday => :absent,
- :special => 'reboot',
- :command => '/bin/true >> /dev/null 2>&1',
- :ensure => :present,
- :environment => [
- 'MAILTO=foo@example.com',
- 'SHELL=/bin/sh'
- ],
- :user => :absent,
- :target => 'foobar'
- }
- ])
+ {
+ name: 'real_job',
+ minute: :absent,
+ hour: :absent,
+ weekday: :absent,
+ month: :absent,
+ monthday: :absent,
+ special: :absent,
+ command: '/bin/true',
+ ensure: :present,
+ environment: :absent,
+ user: :absent,
+ target: 'foobar',
+ },
+ {
+ name: 'complex_job',
+ minute: :absent,
+ hour: :absent,
+ weekday: :absent,
+ month: :absent,
+ monthday: :absent,
+ special: 'reboot',
+ command: '/bin/true >> /dev/null 2>&1',
+ ensure: :present,
+ environment: [
+ 'MAILTO=foo@example.com',
+ 'SHELL=/bin/sh',
+ ],
+ user: :absent,
+ target: 'foobar',
+ },
+ ])
end
end
end
- describe ".match" do
- describe "normal records" do
- it "should match when all fields are the same" do
- expect(described_class.match(record,{resource[:name] => resource})).to eq(resource)
+ describe '.match' do
+ describe 'normal records' do
+ it 'matches when all fields are the same' do
+ expect(described_class.match(record, resource[:name] => resource)).to eq(resource)
end
{
- :minute => %w{0 15 31 45},
- :hour => %w{8-18},
- :monthday => %w{30 31},
- :month => %w{12 23},
- :weekday => %w{4},
- :command => '/bin/false',
- :target => 'nobody'
+ minute: ['0', '15', '31', '45'],
+ hour: ['8-18'],
+ monthday: ['30', '31'],
+ month: ['12', '23'],
+ weekday: ['4'],
+ command: '/bin/false',
+ target: 'nobody',
}.each_pair do |field, new_value|
it "should not match a record when #{field} does not match" do
record[field] = new_value
- expect(described_class.match(record,{resource[:name] => resource})).to be_falsey
+ expect(described_class.match(record, resource[:name] => resource)).to be_falsey
end
end
end
- describe "special records" do
- it "should match when all fields are the same" do
- expect(described_class.match(record_special,{resource_special[:name] => resource_special})).to eq(resource_special)
+ describe 'special records' do
+ it 'matches when all fields are the same' do
+ expect(described_class.match(record_special, resource_special[:name] => resource_special)).to eq(resource_special)
end
{
- :special => 'monthly',
- :command => '/bin/false',
- :target => 'root'
+ special: 'monthly',
+ command: '/bin/false',
+ target: 'root',
}.each_pair do |field, new_value|
it "should not match a record when #{field} does not match" do
record_special[field] = new_value
- expect(described_class.match(record_special,{resource_special[:name] => resource_special})).to be_falsey
+ expect(described_class.match(record_special, resource_special[:name] => resource_special)).to be_falsey
end
end
end
- describe "with a resource without a command" do
- it "should not raise an error" do
- expect { described_class.match(record,{resource_sparse[:name] => resource_sparse}) }.to_not raise_error
+ describe 'with a resource without a command' do
+ it 'does not raise an error' do
+ expect { described_class.match(record, resource_sparse[:name] => resource_sparse) }.not_to raise_error
end
end
-
end
end