diff options
author | Tim Smith <tsmith@chef.io> | 2020-08-07 21:16:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-07 21:16:06 -0700 |
commit | 71355f0b8f5a06b73d6a06e218dd9baead3506d8 (patch) | |
tree | 031f0f56b8883ada7466cd1aad056854f2876075 | |
parent | d3a85588a81c0384039d09376adfadc2977de74f (diff) | |
parent | 803a230286b0637208edc96cb0eff86f40b34b24 (diff) | |
download | ohai-71355f0b8f5a06b73d6a06e218dd9baead3506d8.tar.gz |
Merge pull request #1488 from chef/rubocop_Performance_RegexpMatch
Use match? instead of =~ when MatchData is not used
-rw-r--r-- | lib/ohai/plugins/scaleway.rb | 2 | ||||
-rw-r--r-- | spec/unit/plugins/scaleway_spec.rb | 3 |
2 files changed, 3 insertions, 2 deletions
diff --git a/lib/ohai/plugins/scaleway.rb b/lib/ohai/plugins/scaleway.rb index 37343f03..006be6e6 100644 --- a/lib/ohai/plugins/scaleway.rb +++ b/lib/ohai/plugins/scaleway.rb @@ -26,7 +26,7 @@ Ohai.plugin(:Scaleway) do # looks for `scaleway` keyword in kernel command line # @return [Boolean] do we have the keyword or not? def has_scaleway_cmdline? - if ::File.read("/proc/cmdline") =~ /scaleway/ + if ::File.exist?("/proc/cmdline") && /scaleway/.match?(::File.read("/proc/cmdline")) logger.trace("Plugin Scaleway: has_scaleway_cmdline? == true") return true end diff --git a/spec/unit/plugins/scaleway_spec.rb b/spec/unit/plugins/scaleway_spec.rb index 713a8312..f10f1ecb 100644 --- a/spec/unit/plugins/scaleway_spec.rb +++ b/spec/unit/plugins/scaleway_spec.rb @@ -22,7 +22,7 @@ describe Ohai::System, "plugin scaleway" do before do allow(plugin).to receive(:hint?).with("scaleway").and_return(false) - allow(File).to receive(:read).with("/proc/cmdline").and_return(false) + allow(File).to receive(:exist?).with("/proc/cmdline").and_return(false) end shared_examples_for "!scaleway" do @@ -84,6 +84,7 @@ describe Ohai::System, "plugin scaleway" do describe "with scaleway cmdline" do before do + allow(File).to receive(:exist?).with("/proc/cmdline").and_return(true) allow(File).to receive(:read).with("/proc/cmdline").and_return("initrd=initrd showopts console=ttyS0,115200 nousb vga=0 root=/dev/vda scaleway boot=local") end |