summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@getchef.com>2014-03-20 09:53:06 -0700
committerBryan McLellan <btm@getchef.com>2014-03-20 13:06:29 -0700
commitfb9391b81a3eeceff9c730a975a8583ae43fe048 (patch)
treeb62ac6abcfad48d22e7b5550c4d62f8e55dcdb4c
parent7404a1c96c7a29677be2aa0b1fb5abdb8d619373 (diff)
downloadchef-fb9391b81a3eeceff9c730a975a8583ae43fe048.tar.gz
CHEF-4848: Add additional unit tests
-rw-r--r--lib/chef/resource/cron.rb3
-rw-r--r--spec/unit/provider/cron_spec.rb35
-rw-r--r--spec/unit/resource/cron_spec.rb6
3 files changed, 33 insertions, 11 deletions
diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb
index 0a29afd276..be70c8b5a0 100644
--- a/lib/chef/resource/cron.rb
+++ b/lib/chef/resource/cron.rb
@@ -125,7 +125,8 @@ class Chef
error_message << Provider::Cron::WEEKDAY_SYMBOLS.map {|sym| ":#{sym.to_s}"}.join(', ')
error_message << " and a string in crontab format"
if (arg.is_a?(Symbol) && !Provider::Cron::WEEKDAY_SYMBOLS.include?(arg)) ||
- (!arg.is_a?(Symbol) && integerize(arg) > 7)
+ (!arg.is_a?(Symbol) && integerize(arg) > 7) ||
+ (!arg.is_a?(Symbol) && integerize(arg) < 0)
raise RangeError, error_message
end
rescue ArgumentError
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