Skip to content

Commit

Permalink
Make sure plugin returns Errno::ENOENT if scala or sbt don't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
cmluciano committed Mar 15, 2016
1 parent 3c5841c commit cfa740b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
28 changes: 12 additions & 16 deletions lib/ohai/plugins/scala.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,23 @@

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
15 changes: 7 additions & 8 deletions spec/unit/plugins/scala_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -25,7 +25,7 @@
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
Expand Down Expand Up @@ -55,7 +55,6 @@ def setup_plugin
plugin.run
end


it "should set languages[:sbt][:version]" do
expect(plugin.languages[:scala][:sbt]).to eql("0.13.8")
end
Expand All @@ -66,19 +65,19 @@ def setup_plugin
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

0 comments on commit cfa740b

Please sign in to comment.