summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2016-04-15 13:58:17 -0700
committerTim Smith <tsmith84@gmail.com>2016-04-17 14:05:53 -0700
commit63cbc4649ded4ed7b0e122ac8aa861a143c34b28 (patch)
treeed439eb34455b154644eda10341430d1ff5173f0
parentcf5a98504813630898aa9e1c130e0f6e378cea7f (diff)
downloadohai-elixir.tar.gz
Fix Elixir version detection on newer Elixir releaseselixir
Add specs for the new format + error logging + general fixes
-rw-r--r--lib/ohai/plugins/elixir.rb24
-rw-r--r--spec/unit/plugins/elixir_spec.rb40
2 files changed, 40 insertions, 24 deletions
diff --git a/lib/ohai/plugins/elixir.rb b/lib/ohai/plugins/elixir.rb
index 2733b3c2..75fd081b 100644
--- a/lib/ohai/plugins/elixir.rb
+++ b/lib/ohai/plugins/elixir.rb
@@ -15,18 +15,24 @@
Ohai.plugin(:Elixir) do
provides "languages/elixir"
-
depends "languages"
collect_data do
- output = nil
-
- elixir = Mash.new
- so = shell_out("elixir -v")
- if so.exitstatus == 0
- output = so.stdout.split
- elixir[:version] = output[1]
- languages[:elixir] = elixir if elixir[:version]
+ begin
+ so = shell_out("elixir -v")
+ # Sample output:
+ # Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
+ #
+ # Elixir 1.2.4
+ if so.exitstatus == 0
+ elixir = Mash.new
+ if so.stdout =~ /^Elixir (\S*)/
+ elixir[:version] = $1
+ languages[:elixir] = elixir
+ end
+ end
+ rescue Ohai::Exceptions::Exec
+ Ohai::Log.debug('Elixir plugin: Could not shell_out "elixir -v". Skipping plugin')
end
end
end
diff --git a/spec/unit/plugins/elixir_spec.rb b/spec/unit/plugins/elixir_spec.rb
index a82c8179..c3191985 100644
--- a/spec/unit/plugins/elixir_spec.rb
+++ b/spec/unit/plugins/elixir_spec.rb
@@ -17,29 +17,39 @@
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb"))
describe Ohai::System, "plugin elixir" do
+ let(:plugin) { get_plugin("elixir") }
before(:each) do
- @plugin = get_plugin("elixir")
- @plugin[:languages] = Mash.new
- @stdout = "Elixir 1.0.2"
- allow(@plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(0, @stdout, ""))
+ plugin[:languages] = Mash.new
end
- it "should get the elixir version" do
- expect(@plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(0, @stdout, ""))
- @plugin.run
+ it "should shellout to elixir -v" do
+ expect(plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(0, "Elixir 1.0.2", ""))
+ plugin.run
end
- it "should set languages[:elixir][:version]" do
- @plugin.run
- expect(@plugin.languages[:elixir][:version]).to eql("1.0.2")
+ it "sets languages[:elixir][:version] on older elixir" do
+ allow(plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(0, "Elixir 1.0.2", ""))
+ plugin.run
+ expect(plugin.languages[:elixir][:version]).to eql("1.0.2")
end
- it "should not set the languages[:elixir] if elixir command fails" do
- @stdout = "Elixir 1.0.2\n"
- allow(@plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(1, @stdout, ""))
- @plugin.run
- expect(@plugin.languages).not_to have_key(:elixir)
+ it "sets languages[:elixir][:version] on newer elixir" do
+ new_stdout = "Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]\n\nElixir 1.2.4\n"
+ allow(plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(0, new_stdout, ""))
+ plugin.run
+ expect(plugin.languages[:elixir][:version]).to eql("1.2.4")
end
+ it "does not set languages[:elixir] if elixir command fails" do
+ allow(plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(1, "", ""))
+ plugin.run
+ expect(plugin.languages).not_to have_key(:elixir)
+ end
+
+ it "does not set languages[:elixir] if elixir command doesn't exist" do
+ allow(plugin).to receive(:shell_out).and_raise(Ohai::Exceptions::Exec)
+ plugin.run
+ expect(plugin.languages).not_to have_key(:elixir)
+ end
end