summaryrefslogtreecommitdiff
path: root/spec/unit/provider/cron_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/provider/cron_spec.rb')
-rw-r--r--spec/unit/provider/cron_spec.rb350
1 files changed, 175 insertions, 175 deletions
diff --git a/spec/unit/provider/cron_spec.rb b/spec/unit/provider/cron_spec.rb
index 460fb0ca6a..7a917a4f27 100644
--- a/spec/unit/provider/cron_spec.rb
+++ b/spec/unit/provider/cron_spec.rb
@@ -35,7 +35,7 @@ describe Chef::Provider::Cron do
context "with a matching entry in the user's crontab" do
before :each do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -49,18 +49,18 @@ CRONTAB
it "should set cron_exists" do
@provider.load_current_resource
- @provider.cron_exists.should == true
- @provider.cron_empty.should == false
+ expect(@provider.cron_exists).to eq(true)
+ expect(@provider.cron_empty).to eq(false)
end
it "should pull the details out of the cron line" do
cron = @provider.load_current_resource
- cron.time.should == :reboot
- cron.command.should == '/bin/true param1 param2'
+ expect(cron.time).to eq(:reboot)
+ expect(cron.command).to eq('/bin/true param1 param2')
end
it "should pull env vars out" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -75,16 +75,16 @@ HOME=/home/foo
# Another comment
CRONTAB
cron = @provider.load_current_resource
- cron.mailto.should == 'foo@example.com'
- cron.shell.should == '/bin/foosh'
- cron.path.should == '/bin:/foo'
- cron.home.should == '/home/foo'
- cron.time.should == :reboot
- cron.command.should == '/bin/true param1 param2'
+ expect(cron.mailto).to eq('foo@example.com')
+ expect(cron.shell).to eq('/bin/foosh')
+ expect(cron.path).to eq('/bin:/foo')
+ expect(cron.home).to eq('/home/foo')
+ expect(cron.time).to eq(:reboot)
+ expect(cron.command).to eq('/bin/true param1 param2')
end
it "should parse and load generic and standard environment variables from cron entry" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
# Chef Name: cronhole some stuff
MAILTO=warn@example.com
TEST=lol
@@ -93,12 +93,12 @@ FLAG=1
CRONTAB
cron = @provider.load_current_resource
- cron.mailto.should == "warn@example.com"
- cron.environment.should == {"TEST" => "lol", "FLAG" => "1"}
+ expect(cron.mailto).to eq("warn@example.com")
+ expect(cron.environment).to eq({"TEST" => "lol", "FLAG" => "1"})
end
it "should not break with variables that match the cron resource internals" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
# Chef Name: cronhole some stuff
MINUTE=40
REBOOT=midnight
@@ -108,19 +108,19 @@ ENVIRONMENT=production
CRONTAB
cron = @provider.load_current_resource
- cron.time.should == :reboot
- cron.environment.should == {"MINUTE" => "40", "REBOOT" => "midnight", "TEST" => "lol", "ENVIRONMENT" => "production"}
+ expect(cron.time).to eq(:reboot)
+ expect(cron.environment).to eq({"MINUTE" => "40", "REBOOT" => "midnight", "TEST" => "lol", "ENVIRONMENT" => "production"})
end
it "should report the match" do
- Chef::Log.should_receive(:debug).with("Found cron '#{@new_resource.name}'")
+ expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'")
@provider.load_current_resource
end
describe "action_create" do
before :each do
- @provider.stub(:write_crontab)
- @provider.stub(:read_crontab).and_return(nil)
+ allow(@provider).to receive(:write_crontab)
+ allow(@provider).to receive(:read_crontab).and_return(nil)
end
context "when there is no existing crontab" do
@@ -130,7 +130,7 @@ CRONTAB
end
it "should create a crontab with the entry" do
- @provider.should_receive(:write_crontab).with(<<-ENDCRON)
+ expect(@provider).to receive(:write_crontab).with(<<-ENDCRON)
# Chef Name: cronhole some stuff
@reboot /bin/true
ENDCRON
@@ -156,24 +156,24 @@ CRONTAB
describe "when examining the current system state" do
context "with no crontab for the user" do
before :each do
- @provider.stub(:read_crontab).and_return(nil)
+ allow(@provider).to receive(:read_crontab).and_return(nil)
end
it "should set cron_empty" do
@provider.load_current_resource
- @provider.cron_empty.should == true
- @provider.cron_exists.should == false
+ expect(@provider.cron_empty).to eq(true)
+ expect(@provider.cron_exists).to eq(false)
end
it "should report an empty crontab" do
- Chef::Log.should_receive(:debug).with("Cron empty for '#{@new_resource.user}'")
+ expect(Chef::Log).to receive(:debug).with("Cron empty for '#{@new_resource.user}'")
@provider.load_current_resource
end
end
context "with no matching entry in the user's crontab" do
before :each do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: something else
@@ -185,29 +185,29 @@ CRONTAB
it "should not set cron_exists or cron_empty" do
@provider.load_current_resource
- @provider.cron_exists.should == false
- @provider.cron_empty.should == false
+ expect(@provider.cron_exists).to eq(false)
+ expect(@provider.cron_empty).to eq(false)
end
it "should report no entry found" do
- Chef::Log.should_receive(:debug).with("Cron '#{@new_resource.name}' not found")
+ expect(Chef::Log).to receive(:debug).with("Cron '#{@new_resource.name}' not found")
@provider.load_current_resource
end
it "should not fail if there's an existing cron with a numerical argument" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
# Chef Name: foo[bar] (baz)
21 */4 * * * some_prog 1234567
CRONTAB
- lambda {
+ expect {
@provider.load_current_resource
- }.should_not raise_error
+ }.not_to raise_error
end
end
context "with a matching entry in the user's crontab" do
before :each do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -221,23 +221,23 @@ CRONTAB
it "should set cron_exists" do
@provider.load_current_resource
- @provider.cron_exists.should == true
- @provider.cron_empty.should == false
+ expect(@provider.cron_exists).to eq(true)
+ expect(@provider.cron_empty).to eq(false)
end
it "should pull the details out of the cron line" do
cron = @provider.load_current_resource
- cron.minute.should == '*'
- cron.hour.should == '5'
- cron.day.should == '*'
- cron.month.should == '1'
- cron.weekday.should == '*'
- cron.time.should == nil
- cron.command.should == '/bin/true param1 param2'
+ expect(cron.minute).to eq('*')
+ expect(cron.hour).to eq('5')
+ expect(cron.day).to eq('*')
+ expect(cron.month).to eq('1')
+ expect(cron.weekday).to eq('*')
+ expect(cron.time).to eq(nil)
+ expect(cron.command).to eq('/bin/true param1 param2')
end
it "should pull env vars out" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -252,21 +252,21 @@ HOME=/home/foo
# Another comment
CRONTAB
cron = @provider.load_current_resource
- cron.mailto.should == 'foo@example.com'
- cron.shell.should == '/bin/foosh'
- cron.path.should == '/bin:/foo'
- cron.home.should == '/home/foo'
- cron.minute.should == '*'
- cron.hour.should == '5'
- cron.day.should == '*'
- cron.month.should == '1'
- cron.weekday.should == '*'
- cron.time.should == nil
- cron.command.should == '/bin/true param1 param2'
+ expect(cron.mailto).to eq('foo@example.com')
+ expect(cron.shell).to eq('/bin/foosh')
+ expect(cron.path).to eq('/bin:/foo')
+ expect(cron.home).to eq('/home/foo')
+ expect(cron.minute).to eq('*')
+ expect(cron.hour).to eq('5')
+ expect(cron.day).to eq('*')
+ expect(cron.month).to eq('1')
+ expect(cron.weekday).to eq('*')
+ expect(cron.time).to eq(nil)
+ expect(cron.command).to eq('/bin/true param1 param2')
end
it "should parse and load generic and standard environment variables from cron entry" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
# Chef Name: cronhole some stuff
MAILTO=warn@example.com
TEST=lol
@@ -275,12 +275,12 @@ FLAG=1
CRONTAB
cron = @provider.load_current_resource
- cron.mailto.should == "warn@example.com"
- cron.environment.should == {"TEST" => "lol", "FLAG" => "1"}
+ expect(cron.mailto).to eq("warn@example.com")
+ expect(cron.environment).to eq({"TEST" => "lol", "FLAG" => "1"})
end
it "should not break with variabels that match the cron resource internals" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
# Chef Name: cronhole some stuff
MINUTE=40
HOUR=midnight
@@ -290,20 +290,20 @@ ENVIRONMENT=production
CRONTAB
cron = @provider.load_current_resource
- cron.minute.should == '*'
- cron.hour.should == '5'
- cron.environment.should == {"MINUTE" => "40", "HOUR" => "midnight", "TEST" => "lol", "ENVIRONMENT" => "production"}
+ expect(cron.minute).to eq('*')
+ expect(cron.hour).to eq('5')
+ expect(cron.environment).to eq({"MINUTE" => "40", "HOUR" => "midnight", "TEST" => "lol", "ENVIRONMENT" => "production"})
end
it "should report the match" do
- Chef::Log.should_receive(:debug).with("Found cron '#{@new_resource.name}'")
+ expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'")
@provider.load_current_resource
end
end
context "with a matching entry in the user's crontab using month names and weekday names (#CHEF-3178)" do
before :each do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -317,64 +317,64 @@ CRONTAB
it "should set cron_exists" do
@provider.load_current_resource
- @provider.cron_exists.should == true
- @provider.cron_empty.should == false
+ expect(@provider.cron_exists).to eq(true)
+ expect(@provider.cron_empty).to eq(false)
end
it "should pull the details out of the cron line" do
cron = @provider.load_current_resource
- cron.minute.should == '*'
- cron.hour.should == '5'
- cron.day.should == '*'
- cron.month.should == 'Jan'
- cron.weekday.should == 'Mon'
- cron.command.should == '/bin/true param1 param2'
+ expect(cron.minute).to eq('*')
+ expect(cron.hour).to eq('5')
+ expect(cron.day).to eq('*')
+ expect(cron.month).to eq('Jan')
+ expect(cron.weekday).to eq('Mon')
+ expect(cron.command).to eq('/bin/true param1 param2')
end
it "should report the match" do
- Chef::Log.should_receive(:debug).with("Found cron '#{@new_resource.name}'")
+ expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'")
@provider.load_current_resource
end
end
context "with a matching entry without a crontab line" do
it "should set cron_exists and leave current_resource values at defaults" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
CRONTAB
cron = @provider.load_current_resource
- @provider.cron_exists.should == true
- cron.minute.should == '*'
- cron.hour.should == '*'
- cron.day.should == '*'
- cron.month.should == '*'
- cron.weekday.should == '*'
- cron.time.should == nil
- cron.command.should == nil
+ expect(@provider.cron_exists).to eq(true)
+ expect(cron.minute).to eq('*')
+ expect(cron.hour).to eq('*')
+ expect(cron.day).to eq('*')
+ expect(cron.month).to eq('*')
+ expect(cron.weekday).to eq('*')
+ expect(cron.time).to eq(nil)
+ expect(cron.command).to eq(nil)
end
it "should not pick up a commented out crontab line" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
#* 5 * 1 * /bin/true param1 param2
CRONTAB
cron = @provider.load_current_resource
- @provider.cron_exists.should == true
- cron.minute.should == '*'
- cron.hour.should == '*'
- cron.day.should == '*'
- cron.month.should == '*'
- cron.weekday.should == '*'
- cron.time.should == nil
- cron.command.should == nil
+ expect(@provider.cron_exists).to eq(true)
+ expect(cron.minute).to eq('*')
+ expect(cron.hour).to eq('*')
+ expect(cron.day).to eq('*')
+ expect(cron.month).to eq('*')
+ expect(cron.weekday).to eq('*')
+ expect(cron.time).to eq(nil)
+ expect(cron.command).to eq(nil)
end
it "should not pick up a later crontab entry" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -385,14 +385,14 @@ CRONTAB
# Another comment
CRONTAB
cron = @provider.load_current_resource
- @provider.cron_exists.should == true
- cron.minute.should == '*'
- cron.hour.should == '*'
- cron.day.should == '*'
- cron.month.should == '*'
- cron.weekday.should == '*'
- cron.time.should == nil
- cron.command.should == nil
+ expect(@provider.cron_exists).to eq(true)
+ expect(cron.minute).to eq('*')
+ expect(cron.hour).to eq('*')
+ expect(cron.day).to eq('*')
+ expect(cron.month).to eq('*')
+ expect(cron.weekday).to eq('*')
+ expect(cron.time).to eq(nil)
+ expect(cron.command).to eq(nil)
end
end
end
@@ -409,35 +409,35 @@ CRONTAB
[:minute, :hour, :day, :month, :weekday, :command, :mailto, :path, :shell, :home].each do |attribute|
it "should return true if #{attribute} doesn't match" do
@new_resource.send(attribute, "something_else")
- @provider.cron_different?.should eql(true)
+ expect(@provider.cron_different?).to eql(true)
end
end
it "should return true if special time string doesn't match" do
@new_resource.send(:time, :reboot)
- @provider.cron_different?.should eql(true)
+ expect(@provider.cron_different?).to eql(true)
end
it "should return true if environment doesn't match" do
@new_resource.environment "FOO" => "something_else"
- @provider.cron_different?.should eql(true)
+ expect(@provider.cron_different?).to eql(true)
end
it "should return true if mailto doesn't match" do
@current_resource.mailto "foo@bar.com"
@new_resource.mailto(nil)
- @provider.cron_different?.should eql(true)
+ expect(@provider.cron_different?).to eql(true)
end
it "should return false if the objects are identical" do
- @provider.cron_different?.should == false
+ expect(@provider.cron_different?).to eq(false)
end
end
describe "action_create" do
before :each do
- @provider.stub(:write_crontab)
- @provider.stub(:read_crontab).and_return(nil)
+ allow(@provider).to receive(:write_crontab)
+ allow(@provider).to receive(:read_crontab).and_return(nil)
end
context "when there is no existing crontab" do
@@ -447,7 +447,7 @@ CRONTAB
end
it "should create a crontab with the entry" do
- @provider.should_receive(:write_crontab).with(<<-ENDCRON)
+ expect(@provider).to receive(:write_crontab).with(<<-ENDCRON)
# Chef Name: cronhole some stuff
30 * * * * /bin/true
ENDCRON
@@ -460,7 +460,7 @@ CRONTAB
@new_resource.shell '/bin/foosh'
@new_resource.home '/home/foo'
@new_resource.environment "TEST" => "LOL"
- @provider.should_receive(:write_crontab).with(<<-ENDCRON)
+ expect(@provider).to receive(:write_crontab).with(<<-ENDCRON)
# Chef Name: cronhole some stuff
MAILTO=foo@example.com
PATH=/usr/bin:/my/custom/path
@@ -474,11 +474,11 @@ TEST=LOL
it "should mark the resource as updated" do
@provider.run_action(:create)
- @new_resource.should be_updated_by_last_action
+ expect(@new_resource).to be_updated_by_last_action
end
it "should log the action" do
- Chef::Log.should_receive(:info).with("cron[cronhole some stuff] added crontab entry")
+ expect(Chef::Log).to receive(:info).with("cron[cronhole some stuff] added crontab entry")
@provider.run_action(:create)
end
end
@@ -486,7 +486,7 @@ TEST=LOL
context "when there is a crontab with no matching section" do
before :each do
@provider.cron_exists = false
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: something else
@@ -497,7 +497,7 @@ TEST=LOL
end
it "should add the entry to the crontab" do
- @provider.should_receive(:write_crontab).with(<<-ENDCRON)
+ expect(@provider).to receive(:write_crontab).with(<<-ENDCRON)
0 2 * * * /some/other/command
# Chef Name: something else
@@ -516,7 +516,7 @@ TEST=LOL
@new_resource.shell '/bin/foosh'
@new_resource.home '/home/foo'
@new_resource.environment "TEST" => "LOL"
- @provider.should_receive(:write_crontab).with(<<-ENDCRON)
+ expect(@provider).to receive(:write_crontab).with(<<-ENDCRON)
0 2 * * * /some/other/command
# Chef Name: something else
@@ -536,11 +536,11 @@ TEST=LOL
it "should mark the resource as updated" do
@provider.run_action(:create)
- @new_resource.should be_updated_by_last_action
+ expect(@new_resource).to be_updated_by_last_action
end
it "should log the action" do
- Chef::Log.should_receive(:info).with("cron[cronhole some stuff] added crontab entry")
+ expect(Chef::Log).to receive(:info).with("cron[cronhole some stuff] added crontab entry")
@provider.run_action(:create)
end
end
@@ -548,8 +548,8 @@ TEST=LOL
context "when there is a crontab with a matching but different section" do
before :each do
@provider.cron_exists = true
- @provider.stub(:cron_different?).and_return(true)
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:cron_different?).and_return(true)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -562,7 +562,7 @@ TEST=LOL
end
it "should update the crontab entry" do
- @provider.should_receive(:write_crontab).with(<<-ENDCRON)
+ expect(@provider).to receive(:write_crontab).with(<<-ENDCRON)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -581,7 +581,7 @@ TEST=LOL
@new_resource.shell '/bin/foosh'
@new_resource.home '/home/foo'
@new_resource.environment "TEST" => "LOL"
- @provider.should_receive(:write_crontab).with(<<-ENDCRON)
+ expect(@provider).to receive(:write_crontab).with(<<-ENDCRON)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -601,11 +601,11 @@ TEST=LOL
it "should mark the resource as updated" do
@provider.run_action(:create)
- @new_resource.should be_updated_by_last_action
+ expect(@new_resource).to be_updated_by_last_action
end
it "should log the action" do
- Chef::Log.should_receive(:info).with("cron[cronhole some stuff] updated crontab entry")
+ expect(Chef::Log).to receive(:info).with("cron[cronhole some stuff] updated crontab entry")
@provider.run_action(:create)
end
end
@@ -613,16 +613,16 @@ TEST=LOL
context "when there is a crontab with a matching section with no crontab line in it" do
before :each do
@provider.cron_exists = true
- @provider.stub(:cron_different?).and_return(true)
+ allow(@provider).to receive(:cron_different?).and_return(true)
end
it "should add the crontab to the entry" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
CRONTAB
- @provider.should_receive(:write_crontab).with(<<-ENDCRON)
+ expect(@provider).to receive(:write_crontab).with(<<-ENDCRON)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -632,7 +632,7 @@ TEST=LOL
end
it "should not blat any following entries" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -642,7 +642,7 @@ TEST=LOL
# Another comment
CRONTAB
- @provider.should_receive(:write_crontab).with(<<-ENDCRON)
+ expect(@provider).to receive(:write_crontab).with(<<-ENDCRON)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -657,7 +657,7 @@ TEST=LOL
end
it "should handle env vars with no crontab" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -675,7 +675,7 @@ HOME=/home/foo
@new_resource.path '/usr/bin:/my/custom/path'
@new_resource.shell '/bin/foosh'
@new_resource.home '/home/foo'
- @provider.should_receive(:write_crontab).with(<<-ENDCRON)
+ expect(@provider).to receive(:write_crontab).with(<<-ENDCRON)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -697,8 +697,8 @@ HOME=/home/foo
context "when there is a crontab with a matching and identical section" do
before :each do
@provider.cron_exists = true
- @provider.stub(:cron_different?).and_return(false)
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:cron_different?).and_return(false)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -709,18 +709,18 @@ CRONTAB
end
it "should not update the crontab" do
- @provider.should_not_receive(:write_crontab)
+ expect(@provider).not_to receive(:write_crontab)
@provider.run_action(:create)
end
it "should not mark the resource as updated" do
@provider.run_action(:create)
- @new_resource.should_not be_updated_by_last_action
+ expect(@new_resource).not_to be_updated_by_last_action
end
it "should log nothing changed" do
- Chef::Log.should_receive(:debug).with("Found cron '#{@new_resource.name}'")
- Chef::Log.should_receive(:debug).with("Skipping existing cron entry '#{@new_resource.name}'")
+ expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'")
+ expect(Chef::Log).to receive(:debug).with("Skipping existing cron entry '#{@new_resource.name}'")
@provider.run_action(:create)
end
end
@@ -728,8 +728,8 @@ CRONTAB
describe "action_delete" do
before :each do
- @provider.stub(:write_crontab)
- @provider.stub(:read_crontab).and_return(nil)
+ allow(@provider).to receive(:write_crontab)
+ allow(@provider).to receive(:read_crontab).and_return(nil)
end
context "when the user's crontab has no matching section" do
@@ -738,21 +738,21 @@ CRONTAB
end
it "should do nothing" do
- @provider.should_not_receive(:write_crontab)
- Chef::Log.should_not_receive(:info)
+ expect(@provider).not_to receive(:write_crontab)
+ expect(Chef::Log).not_to receive(:info)
@provider.run_action(:delete)
end
it "should not mark the resource as updated" do
@provider.run_action(:delete)
- @new_resource.should_not be_updated_by_last_action
+ expect(@new_resource).not_to be_updated_by_last_action
end
end
context "when the user has a crontab with a matching section" do
before :each do
@provider.cron_exists = true
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -765,7 +765,7 @@ CRONTAB
end
it "should remove the entry" do
- @provider.should_receive(:write_crontab).with(<<-ENDCRON)
+ expect(@provider).to receive(:write_crontab).with(<<-ENDCRON)
0 2 * * * /some/other/command
# Chef Name: something else
@@ -777,7 +777,7 @@ CRONTAB
end
it "should remove any env vars with the entry" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -789,7 +789,7 @@ FOO=test
# Another comment
CRONTAB
- @provider.should_receive(:write_crontab).with(<<-ENDCRON)
+ expect(@provider).to receive(:write_crontab).with(<<-ENDCRON)
0 2 * * * /some/other/command
# Chef Name: something else
@@ -802,11 +802,11 @@ FOO=test
it "should mark the resource as updated" do
@provider.run_action(:delete)
- @new_resource.should be_updated_by_last_action
+ expect(@new_resource).to be_updated_by_last_action
end
it "should log the action" do
- Chef::Log.should_receive(:info).with("#{@new_resource} deleted crontab entry")
+ expect(Chef::Log).to receive(:info).with("#{@new_resource} deleted crontab entry")
@provider.run_action(:delete)
end
end
@@ -817,12 +817,12 @@ FOO=test
end
it "should remove the section" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
CRONTAB
- @provider.should_receive(:write_crontab).with(<<-ENDCRON)
+ expect(@provider).to receive(:write_crontab).with(<<-ENDCRON)
0 2 * * * /some/other/command
ENDCRON
@@ -830,7 +830,7 @@ FOO=test
end
it "should not blat following sections" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -840,7 +840,7 @@ FOO=test
# Another comment
CRONTAB
- @provider.should_receive(:write_crontab).with(<<-ENDCRON)
+ expect(@provider).to receive(:write_crontab).with(<<-ENDCRON)
0 2 * * * /some/other/command
#30 * * 3 * /bin/true
@@ -853,7 +853,7 @@ FOO=test
end
it "should remove any envvars with the section" do
- @provider.stub(:read_crontab).and_return(<<-CRONTAB)
+ allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB)
0 2 * * * /some/other/command
# Chef Name: cronhole some stuff
@@ -864,7 +864,7 @@ MAILTO=foo@example.com
# Another comment
CRONTAB
- @provider.should_receive(:write_crontab).with(<<-ENDCRON)
+ expect(@provider).to receive(:write_crontab).with(<<-ENDCRON)
0 2 * * * /some/other/command
#30 * * 3 * /bin/true
@@ -889,17 +889,17 @@ MAILTO=foo@example.com
# Another comment
CRONTAB
- @provider.stub(:popen4).and_yield(1234, StringIO.new, @stdout, StringIO.new).and_return(@status)
+ allow(@provider).to receive(:popen4).and_yield(1234, StringIO.new, @stdout, StringIO.new).and_return(@status)
end
it "should call crontab -l with the user" do
- @provider.should_receive(:popen4).with("crontab -l -u #{@new_resource.user}").and_return(@status)
+ expect(@provider).to receive(:popen4).with("crontab -l -u #{@new_resource.user}").and_return(@status)
@provider.send(:read_crontab)
end
it "should return the contents of the crontab" do
crontab = @provider.send(:read_crontab)
- crontab.should == <<-CRONTAB
+ expect(crontab).to eq <<-CRONTAB
0 2 * * * /some/other/command
# Chef Name: something else
@@ -911,16 +911,16 @@ MAILTO=foo@example.com
it "should return nil if the user has no crontab" do
status = double("Status", :exitstatus => 1)
- @provider.stub(:popen4).and_return(status)
- @provider.send(:read_crontab).should == nil
+ allow(@provider).to receive(:popen4).and_return(status)
+ expect(@provider.send(:read_crontab)).to eq(nil)
end
it "should raise an exception if another error occurs" do
status = double("Status", :exitstatus => 2)
- @provider.stub(:popen4).and_return(status)
- lambda do
+ allow(@provider).to receive(:popen4).and_return(status)
+ expect do
@provider.send(:read_crontab)
- end.should raise_error(Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: 2")
+ end.to raise_error(Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: 2")
end
end
@@ -928,24 +928,24 @@ MAILTO=foo@example.com
before :each do
@status = double("Status", :exitstatus => 0)
@stdin = StringIO.new
- @provider.stub(:popen4).and_yield(1234, @stdin, StringIO.new, StringIO.new).and_return(@status)
+ allow(@provider).to receive(:popen4).and_yield(1234, @stdin, StringIO.new, StringIO.new).and_return(@status)
end
it "should call crontab for the user" do
- @provider.should_receive(:popen4).with("crontab -u #{@new_resource.user} -", :waitlast => true).and_return(@status)
+ expect(@provider).to receive(:popen4).with("crontab -u #{@new_resource.user} -", :waitlast => true).and_return(@status)
@provider.send(:write_crontab, "Foo")
end
it "should write the given string to the crontab command" do
@provider.send(:write_crontab, "Foo\n# wibble\n wah!!")
- @stdin.string.should == "Foo\n# wibble\n wah!!"
+ expect(@stdin.string).to eq("Foo\n# wibble\n wah!!")
end
it "should raise an exception if the command returns non-zero" do
- @status.stub(:exitstatus).and_return(1)
- lambda do
+ allow(@status).to receive(:exitstatus).and_return(1)
+ expect do
@provider.send(:write_crontab, "Foo")
- end.should raise_error(Chef::Exceptions::Cron, "Error updating state of #{@new_resource.name}, exit: 1")
+ end.to raise_error(Chef::Exceptions::Cron, "Error updating state of #{@new_resource.name}, exit: 1")
end
it "should raise an exception if the command die's and parent tries to write" do
@@ -954,14 +954,14 @@ MAILTO=foo@example.com
raise Errno::EPIPE, "Test"
end
end
- @status.stub(:exitstatus).and_return(1)
- @provider.stub(:popen4).and_yield(1234, WriteErrPipe.new, StringIO.new, StringIO.new).and_return(@status)
+ allow(@status).to receive(:exitstatus).and_return(1)
+ allow(@provider).to receive(:popen4).and_yield(1234, WriteErrPipe.new, StringIO.new, StringIO.new).and_return(@status)
- Chef::Log.should_receive(:debug).with("Broken pipe - Test")
+ expect(Chef::Log).to receive(:debug).with("Broken pipe - Test")
- lambda do
+ expect do
@provider.send(:write_crontab, "Foo")
- end.should raise_error(Chef::Exceptions::Cron, "Error updating state of #{@new_resource.name}, exit: 1")
+ end.to raise_error(Chef::Exceptions::Cron, "Error updating state of #{@new_resource.name}, exit: 1")
end
end
@@ -970,7 +970,7 @@ MAILTO=foo@example.com
context "when weekday is symbol" do
it "should return weekday in crontab format" do
@new_resource.weekday :wednesday
- @provider.send(:weekday_in_crontab).should eq("3")
+ expect(@provider.send(:weekday_in_crontab)).to eq("3")
end
it "should raise an error with an unknown weekday" do
@@ -981,7 +981,7 @@ MAILTO=foo@example.com
context "when weekday is a number in a string" do
it "should return the string" do
@new_resource.weekday "3"
- @provider.send(:weekday_in_crontab).should eq("3")
+ expect(@provider.send(:weekday_in_crontab)).to eq("3")
end
it "should raise an error with an out of range number" do
@@ -992,14 +992,14 @@ MAILTO=foo@example.com
context "when weekday is string with the name of the week" do
it "should return the string" do
@new_resource.weekday "mon"
- @provider.send(:weekday_in_crontab).should eq("mon")
+ expect(@provider.send(:weekday_in_crontab)).to eq("mon")
end
end
context "when weekday is an integer" do
it "should return the integer" do
@new_resource.weekday 1
- @provider.send(:weekday_in_crontab).should eq("1")
+ expect(@provider.send(:weekday_in_crontab)).to eq("1")
end
it "should raise an error with an out of range integer" do