diff options
author | cmluciano <cmluciano@us.ibm.com> | 2015-10-13 18:39:20 -0400 |
---|---|---|
committer | cmluciano <cmluciano@us.ibm.com> | 2016-03-15 15:07:35 -0400 |
commit | cfa740ba9fba923b70bec7e393293b8efee097be (patch) | |
tree | 71a725c7c92daf95fe4a175e520f2e68e5a1cf4d | |
parent | 3c5841ccee64e0bd7056d209760baed34b1ebe47 (diff) | |
download | ohai-cfa740ba9fba923b70bec7e393293b8efee097be.tar.gz |
Make sure plugin returns Errno::ENOENT if scala or sbt don't exist
-rw-r--r-- | lib/ohai/plugins/scala.rb | 28 | ||||
-rw-r--r-- | spec/unit/plugins/scala_spec.rb | 15 |
2 files changed, 19 insertions, 24 deletions
diff --git a/lib/ohai/plugins/scala.rb b/lib/ohai/plugins/scala.rb index dd809a92..2666b66b 100644 --- a/lib/ohai/plugins/scala.rb +++ b/lib/ohai/plugins/scala.rb @@ -21,27 +21,23 @@ Ohai.plugin(:Scala) do collect_data(:default) do # Check for scala - begin - output = nil + output = nil - scala = Mash.new - so = shell_out("scala -version") - if so.exitstatus == 0 - output = so.stdout.split - scala[:version] = output[4] - languages[:scala] = scala if scala[:version] - end + scala = Mash.new + so = shell_out("scala -version") + if so.exitstatus == 0 + output = so.stdout.split + scala[:version] = output[4] + languages[:scala] = scala if scala[:version] end # Check for sbt - begin - output = nil + output = nil - so = shell_out("sbt --version") - if so.exitstatus == 0 - output = so.stdout.split - scala[:sbt] = output[3] if scala[:version] - end + so = shell_out("sbt --version") + if so.exitstatus == 0 + output = so.stdout.split + scala[:sbt] = output[3] if scala[:version] end end end diff --git a/spec/unit/plugins/scala_spec.rb b/spec/unit/plugins/scala_spec.rb index 85775b5d..3fbfff69 100644 --- a/spec/unit/plugins/scala_spec.rb +++ b/spec/unit/plugins/scala_spec.rb @@ -15,7 +15,7 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')) +require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) describe Ohai::System, "plugin scala" do @@ -25,7 +25,7 @@ describe Ohai::System, "plugin scala" do end end - let(:scala_out) {"Scala code runner version 2.11.6 -- Copyright 2002-2013, LAMP/EPFL"} + let(:scala_out) { "Scala code runner version 2.11.6 -- Copyright 2002-2013, LAMP/EPFL" } let(:sbt_out) { "sbt launcher version 0.13.8" } def setup_plugin @@ -55,7 +55,6 @@ describe Ohai::System, "plugin scala" do plugin.run end - it "should set languages[:sbt][:version]" do expect(plugin.languages[:scala][:sbt]).to eql("0.13.8") end @@ -66,19 +65,19 @@ describe Ohai::System, "plugin scala" do before(:each) do allow(plugin).to receive(:shell_out) .with("scala -version") - .and_return(mock_shell_out(1, scala_out, "")) + .and_raise( Errno::ENOENT) + allow(plugin).to receive(:shell_out) .with("sbt --version") - .and_return(mock_shell_out(1, sbt_out, "")) - plugin.run + .and_raise( Errno::ENOENT) end it "should not set the languages[:scala] if scala command fails" do expect(plugin.languages).not_to have_key(:scala) end - it "should not set the languages[:scala] if scala command fails" do - expect(plugin.languages).not_to have_key(:scala) + it "should not set the languages[:scala][:sbt] if sbt command fails" do + expect(plugin.languages).not_to have_key(:sbt) end end end |