diff options
author | Bryan McLellan <btm@getchef.com> | 2014-03-20 09:53:06 -0700 |
---|---|---|
committer | Bryan McLellan <btm@getchef.com> | 2014-03-20 13:06:29 -0700 |
commit | fb9391b81a3eeceff9c730a975a8583ae43fe048 (patch) | |
tree | b62ac6abcfad48d22e7b5550c4d62f8e55dcdb4c /spec/unit | |
parent | 7404a1c96c7a29677be2aa0b1fb5abdb8d619373 (diff) | |
download | chef-fb9391b81a3eeceff9c730a975a8583ae43fe048.tar.gz |
CHEF-4848: Add additional unit tests
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/provider/cron_spec.rb | 35 | ||||
-rw-r--r-- | spec/unit/resource/cron_spec.rb | 6 |
2 files changed, 31 insertions, 10 deletions
diff --git a/spec/unit/provider/cron_spec.rb b/spec/unit/provider/cron_spec.rb index 181ab23d7e..56e9b4a485 100644 --- a/spec/unit/provider/cron_spec.rb +++ b/spec/unit/provider/cron_spec.rb @@ -836,19 +836,42 @@ MAILTO=foo@example.com describe "weekday_in_crontab" do context "when weekday is symbol" do - before do - @new_resource.weekday :wednesday - end it "should return weekday in crontab format" do + @new_resource.weekday :wednesday @provider.send(:weekday_in_crontab).should eq("3") end + + it "should raise an error with an unknown weekday" do + expect { @new_resource.weekday :caturday }.to raise_error(RangeError) + end end - context "when weekday is string" do - before do + + 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") + end + + it "should raise an error with an out of range number" do + expect { @new_resource.weekday "-1" }.to raise_error(RangeError) end + end + + context "when weekday is string with the name of the week" do it "should return the string" do - @provider.send(:weekday_in_crontab).should eq("3") + @new_resource.weekday "mon" + @provider.send(:weekday_in_crontab).should 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") + end + + it "should raise an error with an out of range integer" do + expect { @new_resource.weekday 45 }.to raise_error(RangeError) end end end diff --git a/spec/unit/resource/cron_spec.rb b/spec/unit/resource/cron_spec.rb index 4c83fbaa2c..cf821e3d32 100644 --- a/spec/unit/resource/cron_spec.rb +++ b/spec/unit/resource/cron_spec.rb @@ -145,12 +145,10 @@ describe Chef::Resource::Cron do describe "weekday" do it "should reject any weekday over 7" do - error_message = "You provided '8' as a weekday, acceptable values are :sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday and a string in crontab format" - lambda { @resource.weekday "8" }.should raise_error(RangeError, error_message) + lambda { @resource.weekday "8" }.should raise_error(RangeError) end it "should reject any symbols which don't represent day of week" do - error_message = "You provided 'foo' as a weekday, acceptable values are :sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday and a string in crontab format" - lambda { @resource.weekday :foo }.should raise_error(RangeError, error_message) + lambda { @resource.weekday :foo }.should raise_error(RangeError) end end |