diff options
author | Ryota Arai <ryota.arai@gmail.com> | 2013-12-19 23:06:47 +0900 |
---|---|---|
committer | Bryan McLellan <btm@getchef.com> | 2014-03-20 13:06:29 -0700 |
commit | 7404a1c96c7a29677be2aa0b1fb5abdb8d619373 (patch) | |
tree | b515d65b99e0899cf0c0a8575e71182b872b12d9 | |
parent | aef824f3f6e6300547f96436aab02cfe799c3e12 (diff) | |
download | chef-7404a1c96c7a29677be2aa0b1fb5abdb8d619373.tar.gz |
Show a short message for invalid value for weekday.
-rw-r--r-- | lib/chef/resource/cron.rb | 8 | ||||
-rw-r--r-- | spec/unit/resource/cron_spec.rb | 11 |
2 files changed, 15 insertions, 4 deletions
diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb index 72f86bc974..0a29afd276 100644 --- a/lib/chef/resource/cron.rb +++ b/lib/chef/resource/cron.rb @@ -121,8 +121,12 @@ class Chef converted_arg = arg end begin - if !arg.is_a?(Symbol) && integerize(arg) > 7 - raise RangeError + error_message = "You provided '#{arg}' as a weekday, acceptable values are " + 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) + raise RangeError, error_message end rescue ArgumentError end diff --git a/spec/unit/resource/cron_spec.rb b/spec/unit/resource/cron_spec.rb index 355a7f09ba..4c83fbaa2c 100644 --- a/spec/unit/resource/cron_spec.rb +++ b/spec/unit/resource/cron_spec.rb @@ -143,8 +143,15 @@ describe Chef::Resource::Cron do lambda { @resource.month "13" }.should raise_error(RangeError) end - it "should reject any weekday over 7" do - lambda { @resource.weekday "8" }.should raise_error(RangeError) + 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) + 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) + end end it "should convert integer schedule values to a string" do |