summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ohai/plugins/scala.rb35
-rw-r--r--spec/unit/plugins/scala_spec.rb39
2 files changed, 45 insertions, 29 deletions
diff --git a/lib/ohai/plugins/scala.rb b/lib/ohai/plugins/scala.rb
index 2666b66b..fcce9e81 100644
--- a/lib/ohai/plugins/scala.rb
+++ b/lib/ohai/plugins/scala.rb
@@ -20,24 +20,31 @@ Ohai.plugin(:Scala) do
depends "languages"
collect_data(:default) do
- # Check for scala
- 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]
+
+ # Check for scala
+ begin
+ # Scala code runner version 2.11.8 -- Copyright 2002-2016, LAMP/EPFL
+ so = shell_out("scala -version")
+ if so.exitstatus == 0
+ scala[:version] = so.stderr.split[4]
+ end
+ rescue Ohai::Exceptions::Exec
+ # ignore shell_out failures
end
# Check for sbt
- output = nil
-
- so = shell_out("sbt --version")
- if so.exitstatus == 0
- output = so.stdout.split
- scala[:sbt] = output[3] if scala[:version]
+ begin
+ # sbt launcher version 0.13.7
+ so = shell_out("sbt --version")
+ if so.exitstatus == 0
+ scala[:sbt] = Mash.new
+ scala[:sbt][:version] = so.stdout.split[3]
+ end
+ rescue Ohai::Exceptions::Exec
+ # ignore shell_out failures
end
+
+ languages[:scala] = scala unless scala.empty?
end
end
diff --git a/spec/unit/plugins/scala_spec.rb b/spec/unit/plugins/scala_spec.rb
index 3fbfff69..f85c577c 100644
--- a/spec/unit/plugins/scala_spec.rb
+++ b/spec/unit/plugins/scala_spec.rb
@@ -31,20 +31,20 @@ describe Ohai::System, "plugin scala" do
def setup_plugin
allow(plugin).to receive(:shell_out)
.with("scala -version")
- .and_return(mock_shell_out(0, scala_out, ""))
+ .and_return(mock_shell_out(0, "", scala_out))
allow(plugin).to receive(:shell_out)
.with("sbt --version")
.and_return(mock_shell_out(0, sbt_out, ""))
end
- context " if scala is installed" do
+ context "if scala is installed" do
before(:each) do
setup_plugin
plugin.run
end
- it "should set languages[:scala][:version]" do
- expect(plugin.languages[:scala][:version]).to eql("2.11.6")
+ it "sets languages[:scala][:version]" do
+ expect(plugin[:languages][:scala][:version]).to eql("2.11.6")
end
end
@@ -55,29 +55,38 @@ 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")
+ it "sets languages[:scala][:sbt][:version]" do
+ expect(plugin[:languages][:scala][:sbt][:version]).to eql("0.13.8")
end
end
- context "if scala is not installed" do
+ context "if scala/sbt are not installed" do
before(:each) do
allow(plugin).to receive(:shell_out)
+ .and_raise( Ohai::Exceptions::Exec )
+ plugin.run
+ end
+
+ it "does NOT set the languages[:scala] if scala/sbts commands fails" do
+ expect(plugin[:languages]).not_to have_key(:scala)
+ end
+ end
+
+ context "if sbt is not installed" do
+ before(:each) do
+ allow(plugin).to receive(:shell_out)
.with("scala -version")
- .and_raise( Errno::ENOENT)
+ .and_return(mock_shell_out(0, "", scala_out))
allow(plugin).to receive(:shell_out)
.with("sbt --version")
- .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)
+ .and_raise( Ohai::Exceptions::Exec )
+ plugin.run
end
- it "should not set the languages[:scala][:sbt] if sbt command fails" do
- expect(plugin.languages).not_to have_key(:sbt)
+ it "does NOT set the languages[:scala][:sbt] if sbt command fails" do
+ expect(plugin[:languages][:scala]).not_to have_key(:sbt)
end
end
end