summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-08-18 16:24:21 -0700
committerTim Smith <tsmith84@gmail.com>2020-08-18 16:24:21 -0700
commit4f03c043d749f6caab625b27dd2d65f6f81ecfdd (patch)
treeaf20bda1c18cb15ff4c0538089e1bfa4ee9ac789
parent621caccc151dfbdddb29adfec57aef91ff3d06c5 (diff)
downloadchef-4f03c043d749f6caab625b27dd2d65f6f81ecfdd.tar.gz
Use .error? and make sure not to raise too early
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/timezone.rb6
-rw-r--r--spec/unit/resource/timezone_spec.rb4
2 files changed, 5 insertions, 5 deletions
diff --git a/lib/chef/resource/timezone.rb b/lib/chef/resource/timezone.rb
index 7ed67860cd..01d6967283 100644
--- a/lib/chef/resource/timezone.rb
+++ b/lib/chef/resource/timezone.rb
@@ -75,7 +75,7 @@ class Chef
# @return [String] timezone id
def current_windows_tz
tz_shellout = shell_out("tzutil /g")
- raise "There was an error running the tzutil command" if tz_shellout.exitstatus == 1
+ raise "There was an error running the tzutil command" if tz_shellout.error?
tz_shellout.stdout.strip
end
@@ -85,8 +85,8 @@ class Chef
# @since 16.5
# @return [String] timezone id
def current_systemd_tz
- tz_shellout = shell_out!(["/usr/bin/timedatectl", "status"])
- raise "There was an error running the timedatectl command" if tz_shellout.exitstatus == 1
+ tz_shellout = shell_out(["/usr/bin/timedatectl", "status"])
+ raise "There was an error running the timedatectl command" if tz_shellout.error?
# https://rubular.com/r/eV68MX9XXbyG4k
/Time zone: (.*) \(.*/.match(tz_shellout.stdout)[1]
diff --git a/spec/unit/resource/timezone_spec.rb b/spec/unit/resource/timezone_spec.rb
index b48a69e103..889d50207f 100644
--- a/spec/unit/resource/timezone_spec.rb
+++ b/spec/unit/resource/timezone_spec.rb
@@ -26,7 +26,7 @@ describe Chef::Resource::Timezone do
# note: This weird indention is correct
let(:shellout_timedatectl) do
- double("shell_out!", exitstatus: 0, error?: false, stdout: <<-OUTPUT)
+ double("shell_out", exitstatus: 0, error?: false, stdout: <<-OUTPUT)
Local time: Tue 2020-08-18 20:55:05 UTC
Universal time: Tue 2020-08-18 20:55:05 UTC
RTC time: Tue 2020-08-18 20:55:05
@@ -80,7 +80,7 @@ systemd-timesyncd.service active: yes
describe "#current_systemd_tz?" do
it "returns the TZ" do
- expect(resource).to receive(:shell_out!).and_return(shellout_timedatectl)
+ expect(resource).to receive(:shell_out).and_return(shellout_timedatectl)
expect(resource.current_systemd_tz).to eql("Etc/UTC")
end
end