From 849d8c7ebc8cce10e1b0a3fd14365f45196f9d6e Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Wed, 13 Apr 2016 16:19:40 -0700 Subject: Fix the scala plugin There were several problems with the scala plugin: 1) scala -version is returned on stderr not stdout so we were never setting this and thus the plugin never ran 2) If sbt or scala weren't installed it threw exceptions 3) we were storing shell outs value in the output value for no real reason 4) if scala failed for some reason, but sbt succeeded we weren't setting the sbt values since were relied on scala[:version] being set 5) the specs incorrectly mocked scala output to stdout 6) the specs that checked to make sure values weren't set didn't actually run the plugin so they would always no find scala's key While I was here I moved the version key for sbt into it's own key. This would allow us to add other sbt values in the future if we found them. If we make version to top level value we lose that ability forever. --- spec/unit/plugins/scala_spec.rb | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'spec/unit') 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 -- cgit v1.2.1