diff options
author | Tim Smith <tsmith@chef.io> | 2016-04-22 09:22:13 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2016-04-22 09:22:13 -0700 |
commit | dca7249654e11ac428bd481d4881ac8be6592901 (patch) | |
tree | 35742a9b9f1399caea2ed665fb04d392683dcded | |
parent | a40ff2f882ebf5cad51a7151571395392d226b0c (diff) | |
parent | 3a1f1b1a81116392c1ebbef975a9e59dea9a827a (diff) | |
download | ohai-dca7249654e11ac428bd481d4881ac8be6592901.tar.gz |
Merge pull request #805 from chef/plugin_cleanup
Language plugins: Improve failure logging, update specs, general cleanup
-rw-r--r-- | lib/ohai/plugins/c.rb | 16 | ||||
-rw-r--r-- | lib/ohai/plugins/elixir.rb | 8 | ||||
-rw-r--r-- | lib/ohai/plugins/go.rb | 18 | ||||
-rw-r--r-- | lib/ohai/plugins/groovy.rb | 22 | ||||
-rw-r--r-- | lib/ohai/plugins/java.rb | 34 | ||||
-rw-r--r-- | lib/ohai/plugins/lua.rb | 21 | ||||
-rw-r--r-- | lib/ohai/plugins/mono.rb | 4 | ||||
-rw-r--r-- | lib/ohai/plugins/nodejs.rb | 24 | ||||
-rw-r--r-- | lib/ohai/plugins/perl.rb | 31 | ||||
-rw-r--r-- | lib/ohai/plugins/php.rb | 38 | ||||
-rw-r--r-- | lib/ohai/plugins/powershell.rb | 56 | ||||
-rw-r--r-- | lib/ohai/plugins/python.rb | 28 | ||||
-rw-r--r-- | lib/ohai/plugins/ruby.rb | 1 | ||||
-rw-r--r-- | lib/ohai/plugins/rust.rb | 20 | ||||
-rw-r--r-- | lib/ohai/plugins/scala.rb | 10 | ||||
-rw-r--r-- | spec/unit/plugins/erlang_spec.rb | 7 | ||||
-rw-r--r-- | spec/unit/plugins/go_spec.rb | 34 | ||||
-rw-r--r-- | spec/unit/plugins/groovy_spec.rb | 48 | ||||
-rw-r--r-- | spec/unit/plugins/java_spec.rb | 174 | ||||
-rw-r--r-- | spec/unit/plugins/lua_spec.rb | 33 | ||||
-rw-r--r-- | spec/unit/plugins/mono_spec.rb | 13 | ||||
-rw-r--r-- | spec/unit/plugins/nodejs_spec.rb | 34 | ||||
-rw-r--r-- | spec/unit/plugins/perl_spec.rb | 46 | ||||
-rw-r--r-- | spec/unit/plugins/powershell_spec.rb | 33 | ||||
-rw-r--r-- | spec/unit/plugins/python_spec.rb | 6 |
25 files changed, 425 insertions, 334 deletions
diff --git a/lib/ohai/plugins/c.rb b/lib/ohai/plugins/c.rb index 81271f80..e5107cdc 100644 --- a/lib/ohai/plugins/c.rb +++ b/lib/ohai/plugins/c.rb @@ -25,9 +25,13 @@ Ohai.plugin(:C) do def collect(cmd, &block) so = shell_out(cmd) - yield(so) if so.exitstatus == 0 + if so.exitstatus == 0 + yield(so) + else + Ohai::Log.debug("Plugin C '#{cmd}' failed. Skipping data.") + end rescue Ohai::Exceptions::Exec - # ignore + Ohai::Log.debug("Plugin C '#{cmd}' binary could not be found. Skipping data.") end collect_data do @@ -35,6 +39,12 @@ Ohai.plugin(:C) do #gcc collect("gcc -v") do |so| + # Sample output: + # Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 + # Apple LLVM version 7.3.0 (clang-703.0.29) + # Target: x86_64-apple-darwin15.4.0 + # Thread model: posix + # InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin description = so.stderr.split($/).last output = description.split if output.length >= 3 @@ -112,6 +122,6 @@ Ohai.plugin(:C) do end end - languages[:c] = c if c.keys.length > 0 + languages[:c] = c unless c.empty? end end diff --git a/lib/ohai/plugins/elixir.rb b/lib/ohai/plugins/elixir.rb index 75fd081b..0dc6b1c3 100644 --- a/lib/ohai/plugins/elixir.rb +++ b/lib/ohai/plugins/elixir.rb @@ -24,12 +24,10 @@ Ohai.plugin(:Elixir) do # 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 + if so.exitstatus == 0 && so.stdout =~ /^Elixir (\S*)/ elixir = Mash.new - if so.stdout =~ /^Elixir (\S*)/ - elixir[:version] = $1 - languages[:elixir] = elixir - end + elixir[:version] = $1 + languages[:elixir] = elixir end rescue Ohai::Exceptions::Exec Ohai::Log.debug('Elixir plugin: Could not shell_out "elixir -v". Skipping plugin') diff --git a/lib/ohai/plugins/go.rb b/lib/ohai/plugins/go.rb index 44a97d6c..3748531b 100644 --- a/lib/ohai/plugins/go.rb +++ b/lib/ohai/plugins/go.rb @@ -18,13 +18,17 @@ Ohai.plugin(:Go) do depends "languages" collect_data do - output = nil - go = Mash.new - so = shell_out("go version") - if so.exitstatus == 0 - output = so.stdout.split - go[:version] = output[2].slice!(2..16) - languages[:go] = go if go[:version] + begin + so = shell_out("go version") + # Sample output: + # go version go1.6.1 darwin/amd64 + if so.exitstatus == 0 && so.stdout =~ /go(\S+)/ + go = Mash.new + go[:version] = $1 + languages[:go] = go + end + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Go plugin: Could not shell_out "go version". Skipping plugin') end end end diff --git a/lib/ohai/plugins/groovy.rb b/lib/ohai/plugins/groovy.rb index 044a6e33..7edbb67c 100644 --- a/lib/ohai/plugins/groovy.rb +++ b/lib/ohai/plugins/groovy.rb @@ -18,21 +18,21 @@ Ohai.plugin(:Groovy) do provides "languages/groovy" - depends "languages" collect_data do - output = nil - - groovy = Mash.new - - so = shell_out("groovy -v") - if so.exitstatus == 0 - output = so.stdout.split - if output.length >= 2 - groovy[:version] = output[2] + begin + so = shell_out("groovy -v") + # Sample output: + # Groovy Version: 2.4.6 JVM: 1.8.0_60 Vendor: Oracle Corporation OS: Mac OS X + if so.exitstatus == 0 && so.stdout =~ /Groovy Version: (\S+).*JVM: (\S+)/ + groovy = Mash.new + groovy[:version] = $1 + groovy[:jvm] = $2 + languages[:groovy] = groovy end - languages[:groovy] = groovy if groovy[:version] + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Groovy plugin: Could not shell_out "groovy -v". Skipping plugin') end end end diff --git a/lib/ohai/plugins/java.rb b/lib/ohai/plugins/java.rb index 1130e8b9..b0d482b7 100644 --- a/lib/ohai/plugins/java.rb +++ b/lib/ohai/plugins/java.rb @@ -21,21 +21,29 @@ Ohai.plugin(:Java) do depends "languages" def get_java_info - java = Mash.new - so = shell_out("java -mx64m -version") - if so.exitstatus == 0 - so.stderr.split(/\r?\n/).each do |line| - case line - when /(?:java|openjdk) version \"([0-9\.\_]+)\"/ - java[:version] = $1 - when /^(.+Runtime Environment.*) \((build)\s*(.+)\)$/ - java[:runtime] = { "name" => $1, "build" => $3 } - when /^(.+ (Client|Server) VM) \(build\s*(.+)\)$/ - java[:hotspot] = { "name" => $1, "build" => $3 } + begin + so = shell_out("java -mx64m -version") + # Sample output: + # java version "1.8.0_60" + # Java(TM) SE Runtime Environment (build 1.8.0_60-b27) + # Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode) + if so.exitstatus == 0 + java = Mash.new + so.stderr.split(/\r?\n/).each do |line| + case line + when /(?:java|openjdk) version \"([0-9\.\_]+)\"/ + java[:version] = $1 + when /^(.+Runtime Environment.*) \((build)\s*(.+)\)$/ + java[:runtime] = { "name" => $1, "build" => $3 } + when /^(.+ (Client|Server) VM) \(build\s*(.+)\)$/ + java[:hotspot] = { "name" => $1, "build" => $3 } + end end - end - languages[:java] = java if java[:version] + languages[:java] = java unless java.empty? + end + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Java plugin: Could not shell_out "java -mx64m -version". Skipping plugin') end end diff --git a/lib/ohai/plugins/lua.rb b/lib/ohai/plugins/lua.rb index 0b1a269d..0a6aaeab 100644 --- a/lib/ohai/plugins/lua.rb +++ b/lib/ohai/plugins/lua.rb @@ -18,21 +18,20 @@ Ohai.plugin(:Lua) do provides "languages/lua" - depends "languages" collect_data do - output = nil - - lua = Mash.new - - so = shell_out("lua -v") - if so.exitstatus == 0 - output = so.stderr.split - if output.length >= 1 - lua[:version] = output[1] + begin + so = shell_out("lua -v") + # Sample output: + # Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio + if so.exitstatus == 0 + lua = Mash.new + lua[:version] = so.stderr.split[1] + languages[:lua] = lua if lua[:version] end - languages[:lua] = lua if lua[:version] + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Lua plugin: Could not shell_out "lua -v". Skipping plugin') end end end diff --git a/lib/ohai/plugins/mono.rb b/lib/ohai/plugins/mono.rb index a8bcf6b5..a7c53935 100644 --- a/lib/ohai/plugins/mono.rb +++ b/lib/ohai/plugins/mono.rb @@ -21,8 +21,9 @@ Ohai.plugin(:Mono) do depends "languages" collect_data do - begin + so = shell_out("mono -V") + # Sample output: # Mono JIT compiler version 4.2.3 (Stable 4.2.3.4/832de4b Wed Mar 30 13:57:48 PDT 2016) # Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com # TLS: normal @@ -33,7 +34,6 @@ Ohai.plugin(:Mono) do # Misc: softdebug # LLVM: supported, not enabled. # GC: sgen - so = shell_out("mono -V") if so.exitstatus == 0 mono = Mash.new output = so.stdout.split diff --git a/lib/ohai/plugins/nodejs.rb b/lib/ohai/plugins/nodejs.rb index 1ceef91e..c1bb0848 100644 --- a/lib/ohai/plugins/nodejs.rb +++ b/lib/ohai/plugins/nodejs.rb @@ -18,21 +18,23 @@ Ohai.plugin(:Nodejs) do provides "languages/nodejs" - depends "languages" collect_data do - output = nil - - nodejs = Mash.new - - so = shell_out("node -v") - if so.exitstatus == 0 - output = so.stdout.split - if output.length >= 1 - nodejs[:version] = output[0][1..output[0].length] + begin + so = shell_out("node -v") + # Sample output: + # v5.10.1 + if so.exitstatus == 0 + nodejs = Mash.new + output = so.stdout.split + if output.length >= 1 + nodejs[:version] = output[0][1..output[0].length] + end + languages[:nodejs] = nodejs if nodejs[:version] end - languages[:nodejs] = nodejs if nodejs[:version] + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Nodejs plugin: Could not shell_out "node -v". Skipping plugin') end end end diff --git a/lib/ohai/plugins/perl.rb b/lib/ohai/plugins/perl.rb index 8ec5e75b..dca682e6 100644 --- a/lib/ohai/plugins/perl.rb +++ b/lib/ohai/plugins/perl.rb @@ -18,25 +18,28 @@ Ohai.plugin(:Perl) do provides "languages/perl" - depends "languages" collect_data do - output = nil - - perl = Mash.new - so = shell_out("perl -V:version -V:archname") - if so.exitstatus == 0 - so.stdout.split(/\r?\n/).each do |line| - case line - when /^version=\'(.+)\';$/ - perl[:version] = $1 - when /^archname=\'(.+)\';$/ - perl[:archname] = $1 + begin + so = shell_out("perl -V:version -V:archname") + # Sample output: + # version='5.18.2'; + # archname='darwin-thread-multi-2level'; + if so.exitstatus == 0 + perl = Mash.new + so.stdout.split(/\r?\n/).each do |line| + case line + when /^version=\'(.+)\';$/ + perl[:version] = $1 + when /^archname=\'(.+)\';$/ + perl[:archname] = $1 + end end + languages[:perl] = perl unless perl.empty? end - languages[:perl] = perl + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Perl plugin: Could not shell_out "perl -V:version -V:archname". Skipping plugin') end - end end diff --git a/lib/ohai/plugins/php.rb b/lib/ohai/plugins/php.rb index 3d950403..45c43f53 100644 --- a/lib/ohai/plugins/php.rb +++ b/lib/ohai/plugins/php.rb @@ -20,27 +20,33 @@ Ohai.plugin(:PHP) do provides "languages/php" - depends "languages" collect_data do - php = Mash.new - - so = shell_out("php -v") - if so.exitstatus == 0 - so.stdout.each_line do |line| - case line - when /PHP (\S+).+built: ([^)]+)/ - php[:version] = $1 - php[:builddate] = $2 - when /Zend Engine v([^\s]+),/ - php[:zend_engine_version] = $1 - when /Zend OPcache v([^\s]+),/ - php[:zend_opcache_version] = $1 + begin + so = shell_out("php -v") + # Sample output: + # PHP 5.5.31 (cli) (built: Feb 20 2016 20:33:10) + # Copyright (c) 1997-2015 The PHP Group + # Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies + if so.exitstatus == 0 + php = Mash.new + so.stdout.each_line do |line| + case line + when /PHP (\S+).+built: ([^)]+)/ + php[:version] = $1 + php[:builddate] = $2 + when /Zend Engine v([^\s]+),/ + php[:zend_engine_version] = $1 + when /Zend OPcache v([^\s]+),/ + php[:zend_opcache_version] = $1 + end end - end - languages[:php] = php if php[:version] + languages[:php] = php unless php.empty? + end + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Php plugin: Could not shell_out "php -v". Skipping plugin') end end end diff --git a/lib/ohai/plugins/powershell.rb b/lib/ohai/plugins/powershell.rb index bf315806..59365b65 100644 --- a/lib/ohai/plugins/powershell.rb +++ b/lib/ohai/plugins/powershell.rb @@ -20,34 +20,38 @@ Ohai.plugin(:Powershell) do depends "languages" collect_data(:windows) do - powershell = Mash.new - so = shell_out("powershell.exe -NoLogo -NonInteractive -NoProfile -command $PSVersionTable") - # Sample output: - # - # Name Value - # ---- ----- - # PSVersion 4.0 - # WSManStackVersion 3.0 - # SerializationVersion 1.1.0.1 - # CLRVersion 4.0.30319.34014 - # BuildVersion 6.3.9600.16394 - # PSCompatibleVersions {1.0, 2.0, 3.0, 4.0} - # PSRemotingProtocolVersion 2.2 + begin + so = shell_out("powershell.exe -NoLogo -NonInteractive -NoProfile -command $PSVersionTable") + # Sample output: + # + # Name Value + # ---- ----- + # PSVersion 4.0 + # WSManStackVersion 3.0 + # SerializationVersion 1.1.0.1 + # CLRVersion 4.0.30319.34014 + # BuildVersion 6.3.9600.16394 + # PSCompatibleVersions {1.0, 2.0, 3.0, 4.0} + # PSRemotingProtocolVersion 2.2 - if so.exitstatus == 0 - version_info = {} - so.stdout.strip.each_line do |line| - kv = line.strip.split(/\s+/, 2) - version_info[kv[0]] = kv[1] if kv.length == 2 + if so.exitstatus == 0 + powershell = Mash.new + version_info = {} + so.stdout.strip.each_line do |line| + kv = line.strip.split(/\s+/, 2) + version_info[kv[0]] = kv[1] if kv.length == 2 + end + powershell[:version] = version_info["PSVersion"] + powershell[:ws_man_stack_version] = version_info["WSManStackVersion"] + powershell[:serialization_version] = version_info["SerializationVersion"] + powershell[:clr_version] = version_info["CLRVersion"] + powershell[:build_version] = version_info["BuildVersion"] + powershell[:compatible_versions] = parse_compatible_versions(version_info["PSCompatibleVersions"]) + powershell[:remoting_protocol_version] = version_info["PSRemotingProtocolVersion"] + languages[:powershell] = powershell unless powershell.empty? end - powershell[:version] = version_info["PSVersion"] - powershell[:ws_man_stack_version] = version_info["WSManStackVersion"] - powershell[:serialization_version] = version_info["SerializationVersion"] - powershell[:clr_version] = version_info["CLRVersion"] - powershell[:build_version] = version_info["BuildVersion"] - powershell[:compatible_versions] = parse_compatible_versions(version_info["PSCompatibleVersions"]) - powershell[:remoting_protocol_version] = version_info["PSRemotingProtocolVersion"] - languages[:powershell] = powershell if powershell[:version] + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Powershell plugin: Could not shell_out "powershell.exe -NoLogo -NonInteractive -NoProfile -command $PSVersionTable". Skipping plugin') end end diff --git a/lib/ohai/plugins/python.rb b/lib/ohai/plugins/python.rb index 2e484a1c..749a5f37 100644 --- a/lib/ohai/plugins/python.rb +++ b/lib/ohai/plugins/python.rb @@ -22,20 +22,22 @@ Ohai.plugin(:Python) do depends "languages" collect_data do - output = nil - - python = Mash.new - - so = shell_out("python -c \"import sys; print (sys.version)\"") - - if so.exitstatus == 0 - output = so.stdout.split - python[:version] = output[0] - if output.length >= 6 - python[:builddate] = "%s %s %s %s" % [output[2], output[3], output[4], output[5].delete!(")")] + begin + so = shell_out("python -c \"import sys; print (sys.version)\"") + # Sample output: + # 2.7.11 (default, Dec 26 2015, 17:47:53) + # [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] + if so.exitstatus == 0 + python = Mash.new + output = so.stdout.split + python[:version] = output[0] + if output.length >= 6 + python[:builddate] = "%s %s %s %s" % [output[2], output[3], output[4], output[5].delete!(")")] + end + languages[:python] = python unless python.empty? end - - languages[:python] = python if python[:version] && python[:builddate] + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Python plugin: Could not shell_out "python -c "import sys; print (sys.version)"". Skipping plugin') end end end diff --git a/lib/ohai/plugins/ruby.rb b/lib/ohai/plugins/ruby.rb index a378855c..8a036031 100644 --- a/lib/ohai/plugins/ruby.rb +++ b/lib/ohai/plugins/ruby.rb @@ -18,7 +18,6 @@ Ohai.plugin(:Ruby) do provides "languages/ruby" - depends "languages" def run_ruby(command) diff --git a/lib/ohai/plugins/rust.rb b/lib/ohai/plugins/rust.rb index f268d9cb..0d6435df 100644 --- a/lib/ohai/plugins/rust.rb +++ b/lib/ohai/plugins/rust.rb @@ -15,18 +15,20 @@ Ohai.plugin(:Rust) do provides "languages/rust" - depends "languages" collect_data do - output = nil - - rust = Mash.new - so = shell_out("rustc --version") - if so.exitstatus == 0 - output = so.stdout.split - rust[:version] = output[1] - languages[:rust] = rust if rust[:version] + begin + so = shell_out("rustc --version") + # Sample output: + # rustc 1.7.0 + if so.exitstatus == 0 + rust = Mash.new + rust[:version] = so.stdout.split[1] + languages[:rust] = rust if rust[:version] + end + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Rust plugin: Could not shell_out "rustc --version". Skipping plugin') end end end diff --git a/lib/ohai/plugins/scala.rb b/lib/ohai/plugins/scala.rb index fcce9e81..f847a565 100644 --- a/lib/ohai/plugins/scala.rb +++ b/lib/ohai/plugins/scala.rb @@ -16,21 +16,19 @@ Ohai.plugin(:Scala) do provides "languages/scala", "languages/scala/sbt" - depends "languages" collect_data(:default) do scala = Mash.new - - # Check for scala begin - # Scala code runner version 2.11.8 -- Copyright 2002-2016, LAMP/EPFL so = shell_out("scala -version") + # Sample output: + # Scala code runner version 2.11.8 -- Copyright 2002-2016, LAMP/EPFL if so.exitstatus == 0 scala[:version] = so.stderr.split[4] end rescue Ohai::Exceptions::Exec - # ignore shell_out failures + Ohai::Log.debug('Scala plugin: Could not shell_out "scala -version". Skipping data') end # Check for sbt @@ -42,7 +40,7 @@ Ohai.plugin(:Scala) do scala[:sbt][:version] = so.stdout.split[3] end rescue Ohai::Exceptions::Exec - # ignore shell_out failures + Ohai::Log.debug('Scala plugin: Could not shell_out "sbt --version". Skipping data') end languages[:scala] = scala unless scala.empty? diff --git a/spec/unit/plugins/erlang_spec.rb b/spec/unit/plugins/erlang_spec.rb index 0f407b69..b7f51f14 100644 --- a/spec/unit/plugins/erlang_spec.rb +++ b/spec/unit/plugins/erlang_spec.rb @@ -58,9 +58,14 @@ describe Ohai::System, "plugin erlang" do end it "does not set languages[:erlang] if the erl commands fails" do - allow(plugin).to receive(:shell_out).and_raise(Ohai::Exceptions::Exec) + allow(plugin).to receive(:shell_out).and_return(mock_shell_out(1, "", "")) plugin.run expect(plugin.languages).not_to have_key(:erlang) end + it "does not set languages[:erlang] if the erl 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(:erlang) + end end diff --git a/spec/unit/plugins/go_spec.rb b/spec/unit/plugins/go_spec.rb index 6f1f8809..7bd3cd79 100644 --- a/spec/unit/plugins/go_spec.rb +++ b/spec/unit/plugins/go_spec.rb @@ -16,29 +16,33 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) describe Ohai::System, "plugin go" do + let(:plugin) { get_plugin("go") } before(:each) do - @plugin = get_plugin("go") - @plugin[:languages] = Mash.new - @stdout = "go version go1.1.2 darwin/amd64\n" - allow(@plugin).to receive(:shell_out).with("go version").and_return(mock_shell_out(0, @stdout, "")) + plugin[:languages] = Mash.new + stdout = "go version go1.6.1 darwin/amd64\n" + allow(plugin).to receive(:shell_out).with("go version").and_return(mock_shell_out(0, stdout, "")) end - it "should get the go version" do - expect(@plugin).to receive(:shell_out).with("go version").and_return(mock_shell_out(0, @stdout, "")) - @plugin.run + it "it shells out to get the go version" do + expect(plugin).to receive(:shell_out).with("go version") + plugin.run end - it "should set languages[:go][:version]" do - @plugin.run - expect(@plugin.languages[:go][:version]).to eql("1.1.2") + it "sets languages[:go][:version]" do + plugin.run + expect(plugin.languages[:go][:version]).to eql("1.6.1") end - it "should not set the languages[:go] tree up if go command fails" do - @stdout = "go version go1.1.2 darwin/amd64\n" - allow(@plugin).to receive(:shell_out).with("go version").and_return(mock_shell_out(1, @stdout, "")) - @plugin.run - expect(@plugin.languages).not_to have_key(:go) + it "does not set languages[:go] if go command fails" do + allow(plugin).to receive(:shell_out).with("go version").and_return(mock_shell_out(1, "", "")) + plugin.run + expect(plugin.languages).not_to have_key(:go) end + it "does not set languages[:go] if go 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(:go) + end end diff --git a/spec/unit/plugins/groovy_spec.rb b/spec/unit/plugins/groovy_spec.rb index bbd16c5c..4b614ab3 100644 --- a/spec/unit/plugins/groovy_spec.rb +++ b/spec/unit/plugins/groovy_spec.rb @@ -19,28 +19,48 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) describe Ohai::System, "plugin groovy" do + let(:plugin) { get_plugin("groovy") } before(:each) do - @plugin = get_plugin("groovy") - @plugin[:languages] = Mash.new - @stdout = "Groovy Version: 1.6.3 JVM: 1.6.0_0\n" - allow(@plugin).to receive(:shell_out).with("groovy -v").and_return(mock_shell_out(0, @stdout, "")) + plugin[:languages] = Mash.new end - it "should get the groovy version from running groovy -v" do - expect(@plugin).to receive(:shell_out).with("groovy -v").and_return(mock_shell_out(0, @stdout, "")) - @plugin.run + it "shells out to groovy -v" do + allow(plugin).to receive(:shell_out).with("groovy -v").and_return(mock_shell_out(0, "", "")) + expect(plugin).to receive(:shell_out).with("groovy -v") + plugin.run end - it "should set languages[:groovy][:version]" do - @plugin.run - expect(@plugin.languages[:groovy][:version]).to eql("1.6.3") + it "sets languages[:groovy][:version] on newer groovy versions" do + new_stdout = "Groovy Version: 2.4.6 JVM: 1.8.0_60 Vendor: Oracle Corporation OS: Mac OS X\n" + allow(plugin).to receive(:shell_out).with("groovy -v").and_return(mock_shell_out(0, new_stdout, "")) + plugin.run + expect(plugin.languages[:groovy][:version]).to eql("2.4.6") end - it "should not set the languages[:groovy] tree up if groovy command fails" do - allow(@plugin).to receive(:shell_out).with("groovy -v").and_return(mock_shell_out(1, @stdout, "")) - @plugin.run - expect(@plugin.languages).not_to have_key(:groovy) + it "sets languages[:groovy][:version] on older groovy versions" do + old_stdout = "Groovy Version: 1.6.3 JVM: 1.6.0_0\n" + allow(plugin).to receive(:shell_out).with("groovy -v").and_return(mock_shell_out(0, old_stdout, "")) + plugin.run + expect(plugin.languages[:groovy][:version]).to eql("1.6.3") end + it "sets languages[:groovy][:jvm]" do + new_stdout = "Groovy Version: 2.4.6 JVM: 1.8.0_60 Vendor: Oracle Corporation OS: Mac OS X\n" + allow(plugin).to receive(:shell_out).with("groovy -v").and_return(mock_shell_out(0, new_stdout, "")) + plugin.run + expect(plugin.languages[:groovy][:jvm]).to eql("1.8.0_60") + end + + it "does not set languages[:groovy] if groovy command fails" do + allow(plugin).to receive(:shell_out).with("groovy -v").and_return(mock_shell_out(1, "", "")) + plugin.run + expect(plugin.languages).not_to have_key(:groovy) + end + + it "does not set languages[:groovy] if groovy 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(:groovy) + end end diff --git a/spec/unit/plugins/java_spec.rb b/spec/unit/plugins/java_spec.rb index bf5c7596..a8279caf 100644 --- a/spec/unit/plugins/java_spec.rb +++ b/spec/unit/plugins/java_spec.rb @@ -20,142 +20,149 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") describe Ohai::System, "plugin java (Java5 Client VM)" do + let(:plugin) { get_plugin("java") } + before(:each) do - @plugin = get_plugin("java") - @plugin[:languages] = Mash.new + plugin[:languages] = Mash.new end shared_examples_for "when the JRE is installed" do before do - @stderr = "java version \"1.5.0_16\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)\nJava HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)" - allow(@plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(0, "", @stderr)) + stderr = "java version \"1.5.0_16\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)\nJava HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)" + allow(plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(0, "", stderr)) + end + + it "runs java -mx64m -version" do + expect(plugin).to receive(:shell_out).with("java -mx64m -version") + plugin.run end - it "should run java -mx64m -version" do - expect(@plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(0, "", @stderr)) - @plugin.run + it "sets java[:version]" do + plugin.run + expect(plugin[:languages][:java][:version]).to eql("1.5.0_16") end - it "should set java[:version]" do - @plugin.run - expect(@plugin[:languages][:java][:version]).to eql("1.5.0_16") + it "sets java[:runtime][:name] to runtime name" do + plugin.run + expect(plugin[:languages][:java][:runtime][:name]).to eql("Java(TM) 2 Runtime Environment, Standard Edition") end - it "should set java[:runtime][:name] to runtime name" do - @plugin.run - expect(@plugin[:languages][:java][:runtime][:name]).to eql("Java(TM) 2 Runtime Environment, Standard Edition") + it "sets java[:runtime][:build] to runtime build" do + plugin.run + expect(plugin[:languages][:java][:runtime][:build]).to eql("1.5.0_16-b06-284") end - it "should set java[:runtime][:build] to runtime build" do - @plugin.run - expect(@plugin[:languages][:java][:runtime][:build]).to eql("1.5.0_16-b06-284") + it "sets java[:hotspot][:name] to hotspot name" do + plugin.run + expect(plugin[:languages][:java][:hotspot][:name]).to eql("Java HotSpot(TM) Client VM") end - it "should set java[:hotspot][:name] to hotspot name" do - @plugin.run - expect(@plugin[:languages][:java][:hotspot][:name]).to eql("Java HotSpot(TM) Client VM") + it "sets java[:hotspot][:build] to hotspot build" do + plugin.run + expect(plugin[:languages][:java][:hotspot][:build]).to eql("1.5.0_16-133, mixed mode, sharing") end - it "should set java[:hotspot][:build] to hotspot build" do - @plugin.run - expect(@plugin[:languages][:java][:hotspot][:build]).to eql("1.5.0_16-133, mixed mode, sharing") + it "does not set the languages[:java] tree up if java command fails" do + stderr = "Some error output here" + allow(plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(1, "", stderr)) + plugin.run + expect(plugin[:languages]).not_to have_key(:java) end - it "should not set the languages[:java] tree up if java command fails" do - @stderr = "Some error output here" - allow(@plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(1, "", @stderr)) - @plugin.run - expect(@plugin[:languages]).not_to have_key(:java) + it "does not set the languages[:java] tree up if java 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(:java) end end shared_examples_for "when the Server JRE is installed" do before(:each) do - @stderr = "java version \"1.6.0_22\"\nJava(TM) 2 Runtime Environment (build 1.6.0_22-b04)\nJava HotSpot(TM) Server VM (build 17.1-b03, mixed mode)" - allow(@plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(0, "", @stderr)) + stderr = "java version \"1.6.0_22\"\nJava(TM) 2 Runtime Environment (build 1.6.0_22-b04)\nJava HotSpot(TM) Server VM (build 17.1-b03, mixed mode)" + allow(plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(0, "", stderr)) end - it "should run java -mx64m -version" do - expect(@plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(0, "", @stderr)) - @plugin.run + it "runs java -mx64m -version" do + expect(plugin).to receive(:shell_out).with("java -mx64m -version") + plugin.run end - it "should set java[:version]" do - @plugin.run - expect(@plugin[:languages][:java][:version]).to eql("1.6.0_22") + it "sets java[:version]" do + plugin.run + expect(plugin[:languages][:java][:version]).to eql("1.6.0_22") end - it "should set java[:runtime][:name] to runtime name" do - @plugin.run - expect(@plugin[:languages][:java][:runtime][:name]).to eql("Java(TM) 2 Runtime Environment") + it "sets java[:runtime][:name] to runtime name" do + plugin.run + expect(plugin[:languages][:java][:runtime][:name]).to eql("Java(TM) 2 Runtime Environment") end - it "should set java[:runtime][:build] to runtime build" do - @plugin.run - expect(@plugin[:languages][:java][:runtime][:build]).to eql("1.6.0_22-b04") + it "sets java[:runtime][:build] to runtime build" do + plugin.run + expect(plugin[:languages][:java][:runtime][:build]).to eql("1.6.0_22-b04") end - it "should set java[:hotspot][:name] to hotspot name" do - @plugin.run - expect(@plugin[:languages][:java][:hotspot][:name]).to eql("Java HotSpot(TM) Server VM") + it "sets java[:hotspot][:name] to hotspot name" do + plugin.run + expect(plugin[:languages][:java][:hotspot][:name]).to eql("Java HotSpot(TM) Server VM") end - it "should set java[:hotspot][:build] to hotspot build" do - @plugin.run - expect(@plugin[:languages][:java][:hotspot][:build]).to eql("17.1-b03, mixed mode") + it "sets java[:hotspot][:build] to hotspot build" do + plugin.run + expect(plugin[:languages][:java][:hotspot][:build]).to eql("17.1-b03, mixed mode") end - it "should not set the languages[:java] tree up if java command fails" do - @stderr = "Some error output here" - allow(@plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(0, "", @stderr)) - @plugin.run - expect(@plugin[:languages]).not_to have_key(:java) + it "does not set the languages[:java] tree up if java command fails" do + stderr = "Some error output here" + allow(plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(0, "", stderr)) + plugin.run + expect(plugin[:languages]).not_to have_key(:java) end end shared_examples_for "when the openjdk 1.8 is installed" do before(:each) do - @stderr = "openjdk version \"1.8.0_71\"\nOpenJDK Runtime Environment (build 1.8.0_71-b15)\nOpenJDK 64-Bit Server VM (build 25.71-b15, mixed mode)" - allow(@plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(0, "", @stderr)) + stderr = "openjdk version \"1.8.0_71\"\nOpenJDK Runtime Environment (build 1.8.0_71-b15)\nOpenJDK 64-Bit Server VM (build 25.71-b15, mixed mode)" + allow(plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(0, "", stderr)) end - it "should run java -mx64m -version" do - expect(@plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(0, "", @stderr)) - @plugin.run + it "runs java -mx64m -version" do + expect(plugin).to receive(:shell_out).with("java -mx64m -version") + plugin.run end - it "should set java[:version]" do - @plugin.run - expect(@plugin[:languages][:java][:version]).to eql("1.8.0_71") + it "sets java[:version]" do + plugin.run + expect(plugin[:languages][:java][:version]).to eql("1.8.0_71") end - it "should set java[:runtime][:name] to runtime name" do - @plugin.run - expect(@plugin[:languages][:java][:runtime][:name]).to eql("OpenJDK Runtime Environment") + it "sets java[:runtime][:name] to runtime name" do + plugin.run + expect(plugin[:languages][:java][:runtime][:name]).to eql("OpenJDK Runtime Environment") end - it "should set java[:runtime][:build] to runtime build" do - @plugin.run - expect(@plugin[:languages][:java][:runtime][:build]).to eql("1.8.0_71-b15") + it "sets java[:runtime][:build] to runtime build" do + plugin.run + expect(plugin[:languages][:java][:runtime][:build]).to eql("1.8.0_71-b15") end - it "should set java[:hotspot][:name] to hotspot name" do - @plugin.run - expect(@plugin[:languages][:java][:hotspot][:name]).to eql("OpenJDK 64-Bit Server VM") + it "sets java[:hotspot][:name] to hotspot name" do + plugin.run + expect(plugin[:languages][:java][:hotspot][:name]).to eql("OpenJDK 64-Bit Server VM") end - it "should set java[:hotspot][:build] to hotspot build" do - @plugin.run - expect(@plugin[:languages][:java][:hotspot][:build]).to eql("25.71-b15, mixed mode") + it "sets java[:hotspot][:build] to hotspot build" do + plugin.run + expect(plugin[:languages][:java][:hotspot][:build]).to eql("25.71-b15, mixed mode") end - it "should not set the languages[:java] tree up if java command fails" do - @stderr = "Some error output here" - allow(@plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(0, "", @stderr)) - @plugin.run - expect(@plugin[:languages]).not_to have_key(:java) + it "does not set the languages[:java] tree up if java command fails" do + stderr = "Some error output here" + allow(plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(0, "", stderr)) + plugin.run + expect(plugin[:languages]).not_to have_key(:java) end end @@ -181,14 +188,14 @@ describe Ohai::System, "plugin java (Java5 Client VM)" do end it "detects that it is on a darwin platform" do - expect(@plugin).to be_on_darwin + expect(plugin).to be_on_darwin end context "and real Java is installed" do before do java_home_status = double(Process::Status, :success? => true) java_home_cmd = double(Mixlib::ShellOut, :status => java_home_status) - expect(@plugin).to receive(:shell_out).with("/usr/libexec/java_home").and_return(java_home_cmd) + expect(plugin).to receive(:shell_out).with("/usr/libexec/java_home").and_return(java_home_cmd) end context "and the client JRE is installed" do @@ -206,15 +213,14 @@ describe Ohai::System, "plugin java (Java5 Client VM)" do before do java_home_status = double(Process::Status, :success? => false) java_home_cmd = double(Mixlib::ShellOut, :status => java_home_status) - expect(@plugin).to receive(:shell_out).with("/usr/libexec/java_home").and_return(java_home_cmd) + expect(plugin).to receive(:shell_out).with("/usr/libexec/java_home").and_return(java_home_cmd) end it "does not attempt to get java info" do - expect(@plugin).not_to receive(:shell_out).with("java -mx64m -version") - @plugin.run - expect(@plugin[:languages]).not_to have_key(:java) + expect(plugin).not_to receive(:shell_out).with("java -mx64m -version") + plugin.run + expect(plugin[:languages]).not_to have_key(:java) end end end - end diff --git a/spec/unit/plugins/lua_spec.rb b/spec/unit/plugins/lua_spec.rb index 056f30ee..c994ef17 100644 --- a/spec/unit/plugins/lua_spec.rb +++ b/spec/unit/plugins/lua_spec.rb @@ -22,28 +22,33 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_he describe Ohai::System, "plugin lua" do + let(:plugin) { get_plugin("lua") } + before(:each) do - @plugin = get_plugin("lua") - @plugin[:languages] = Mash.new + plugin[:languages] = Mash.new @stderr = "Lua 5.1.2 Copyright (C) 1994-2008 Lua.org, PUC-Rio\n" - allow(@plugin).to receive(:shell_out).with("lua -v").and_return(mock_shell_out(0, "", @stderr)) + allow(plugin).to receive(:shell_out).with("lua -v").and_return(mock_shell_out(0, "", @stderr)) end - it "should get the lua version from running lua -v" do - expect(@plugin).to receive(:shell_out).with("lua -v").and_return(mock_shell_out(0, "", @stderr)) - @plugin.run + it "gets the lua version from running lua -v" do + expect(plugin).to receive(:shell_out).with("lua -v") + plugin.run end - it "should set languages[:lua][:version]" do - @plugin.run - expect(@plugin.languages[:lua][:version]).to eql("5.1.2") + it "sets languages[:lua][:version]" do + plugin.run + expect(plugin.languages[:lua][:version]).to eql("5.1.2") end - it "should not set the languages[:lua] tree up if lua command fails" do - @stderr = "Lua 5.1.2 Copyright (C) 1994-2008 Lua.org, PUC-Rio\n" - allow(@plugin).to receive(:shell_out).with("lua -v").and_return(mock_shell_out(1, "", @stderr)) - @plugin.run - expect(@plugin.languages).not_to have_key(:lua) + it "does not set languages[:lua] if lua command fails" do + allow(plugin).to receive(:shell_out).with("lua -v").and_return(mock_shell_out(1, "", "")) + plugin.run + expect(plugin.languages).not_to have_key(:lua) end + it "does not set languages[:lua] if lua 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(:lua) + end end diff --git a/spec/unit/plugins/mono_spec.rb b/spec/unit/plugins/mono_spec.rb index 846fb4ff..a45f57ed 100644 --- a/spec/unit/plugins/mono_spec.rb +++ b/spec/unit/plugins/mono_spec.rb @@ -38,25 +38,30 @@ OUT allow(plugin).to receive(:shell_out).with("mono -V").and_return(mock_shell_out(0, @stdout, "")) end - it "should get the mono version from running mono -V" do + it "gets the mono version from running mono -V" do expect(plugin).to receive(:shell_out).with("mono -V").and_return(mock_shell_out(0, @stdout, "")) plugin.run end - it "should set languages[:mono][:version]" do + it "sets languages[:mono][:version]" do plugin.run expect(plugin.languages[:mono][:version]).to eql("4.2.3") end - it "should set languages[:mono][:builddate]" do + it "sets languages[:mono][:builddate]" do plugin.run expect(plugin.languages[:mono][:builddate]).to eql("Wed Mar 30 13:57:48 PDT 2016") end - it "should not set the languages[:mono] tree up if mono command fails" do + it "does not set the languages[:mono] if mono command fails" do allow(plugin).to receive(:shell_out).with("mono -V").and_return(mock_shell_out(1, @stdout, "")) plugin.run expect(plugin.languages).not_to have_key(:mono) end + it "does not set languages[:mono] if mono 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(:mono) + end end diff --git a/spec/unit/plugins/nodejs_spec.rb b/spec/unit/plugins/nodejs_spec.rb index af6af616..a87d5b05 100644 --- a/spec/unit/plugins/nodejs_spec.rb +++ b/spec/unit/plugins/nodejs_spec.rb @@ -22,28 +22,34 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_he describe Ohai::System, "plugin nodejs" do + let(:plugin) { get_plugin("nodejs") } + before(:each) do - @plugin = get_plugin("nodejs") - @plugin[:languages] = Mash.new + plugin[:languages] = Mash.new @stdout = "v0.8.11\n" - allow(@plugin).to receive(:shell_out).with("node -v").and_return(mock_shell_out(0, @stdout, "")) + allow(plugin).to receive(:shell_out).with("node -v").and_return(mock_shell_out(0, @stdout, "")) end - it "should get the nodejs version from running node -v" do - expect(@plugin).to receive(:shell_out).with("node -v").and_return(mock_shell_out(0, @stdout, "")) - @plugin.run + it "gets the nodejs version from running node -v" do + expect(plugin).to receive(:shell_out).with("node -v") + plugin.run end - it "should set languages[:nodejs][:version]" do - @plugin.run - expect(@plugin.languages[:nodejs][:version]).to eql("0.8.11") + it "sets languages[:nodejs][:version]" do + plugin.run + expect(plugin.languages[:nodejs][:version]).to eql("0.8.11") end - it "should not set the languages[:nodejs] tree up if node command fails" do - @stdout = "v0.8.11\n" - allow(@plugin).to receive(:shell_out).with("node -v").and_return(mock_shell_out(1, @stdout, "")) - @plugin.run - expect(@plugin.languages).not_to have_key(:nodejs) + it "does not set the languages[:nodejs] tree up if node command fails" do + allow(plugin).to receive(:shell_out).with("node -v").and_return(mock_shell_out(1, "", "")) + plugin.run + expect(plugin.languages).not_to have_key(:nodejs) + end + + it "does not set languages[:nodejs] if node 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(:nodejs) end end diff --git a/spec/unit/plugins/perl_spec.rb b/spec/unit/plugins/perl_spec.rb index 331ea9a4..47bd686f 100644 --- a/spec/unit/plugins/perl_spec.rb +++ b/spec/unit/plugins/perl_spec.rb @@ -20,39 +20,43 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") describe Ohai::System, "plugin perl" do + let(:plugin) { get_plugin("perl") } + before(:each) do - @plugin = get_plugin("perl") - @plugin[:languages] = Mash.new + plugin[:languages] = Mash.new @stdout = "version='5.8.8';#{$/}archname='darwin-thread-multi-2level';" - allow(@plugin).to receive(:shell_out).with("perl -V:version -V:archname").and_return(mock_shell_out(0, @stdout, "")) + allow(plugin).to receive(:shell_out).with("perl -V:version -V:archname").and_return(mock_shell_out(0, @stdout, "")) end - it "should run perl -V:version -V:archname" do - expect(@plugin).to receive(:shell_out).with("perl -V:version -V:archname").and_return(mock_shell_out(0, @stdout, "")) - @plugin.run + it "runs perl -V:version -V:archname" do + expect(plugin).to receive(:shell_out).with("perl -V:version -V:archname").and_return(mock_shell_out(0, "", "")) + plugin.run end - it "should set languages[:perl][:version]" do - @plugin.run - expect(@plugin.languages[:perl][:version]).to eql("5.8.8") + it "sets languages[:perl][:version]" do + plugin.run + expect(plugin.languages[:perl][:version]).to eql("5.8.8") end - it "should set languages[:perl][:archname]" do - @plugin.run - expect(@plugin.languages[:perl][:archname]).to eql("darwin-thread-multi-2level") + it "sets languages[:perl][:archname]" do + plugin.run + expect(plugin.languages[:perl][:archname]).to eql("darwin-thread-multi-2level") end - it "should set languages[:perl] if perl command succeeds" do - allow(@plugin).to receive(:shell_out).with("perl -V:version -V:archname").and_return(mock_shell_out(0, @stdout, "")) - @plugin.run - expect(@plugin.languages).to have_key(:perl) + it "sets languages[:perl] if perl command succeeds" do + plugin.run + expect(plugin.languages).to have_key(:perl) end - it "should not set languages[:perl] if perl command fails" do - @status = 1 - allow(@plugin).to receive(:shell_out).with("perl -V:version -V:archname").and_return(mock_shell_out(1, @stdout, "")) - @plugin.run - expect(@plugin.languages).not_to have_key(:perl) + it "does not set languages[:perl] if perl command fails" do + allow(plugin).to receive(:shell_out).with("perl -V:version -V:archname").and_return(mock_shell_out(1, "", "")) + plugin.run + expect(plugin.languages).not_to have_key(:perl) end + it "does not set languages[:perl] if perl 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(:perl) + end end diff --git a/spec/unit/plugins/powershell_spec.rb b/spec/unit/plugins/powershell_spec.rb index ae49698c..d96d1622 100644 --- a/spec/unit/plugins/powershell_spec.rb +++ b/spec/unit/plugins/powershell_spec.rb @@ -18,16 +18,17 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) describe Ohai::System, "plugin powershell" do + let(:plugin) { get_plugin("powershell") } + before do stub_const("::RbConfig::CONFIG", { "host_os" => "windows" }) end before(:each) do - @plugin = get_plugin("powershell") - @plugin[:languages] = Mash.new + plugin[:languages] = Mash.new end - it "should set languages[:powershell][:version] for v4" do + it "sets languages[:powershell][:version] for v4" do v4_output = <<END @@ -43,26 +44,26 @@ PSRemotingProtocolVersion 2.2 END - allow(@plugin).to receive(:shell_out).with(anything()).and_return(mock_shell_out(0, v4_output, "")) - @plugin.run - expect(@plugin.languages[:powershell][:version]).to eql("4.0") - expect(@plugin.languages[:powershell][:ws_man_stack_version]).to eql("3.0") - expect(@plugin.languages[:powershell][:serialization_version]).to eql("1.1.0.1") - expect(@plugin.languages[:powershell][:clr_version]).to eql("4.0.30319.34014") - expect(@plugin.languages[:powershell][:build_version]).to eql("6.3.9600.16394") - expect(@plugin.languages[:powershell][:compatible_versions]).to eql(["1.0", "2.0", "3.0", "4.0"]) - expect(@plugin.languages[:powershell][:remoting_protocol_version]).to eql("2.2") + allow(plugin).to receive(:shell_out).with(anything()).and_return(mock_shell_out(0, v4_output, "")) + plugin.run + expect(plugin.languages[:powershell][:version]).to eql("4.0") + expect(plugin.languages[:powershell][:ws_man_stack_version]).to eql("3.0") + expect(plugin.languages[:powershell][:serialization_version]).to eql("1.1.0.1") + expect(plugin.languages[:powershell][:clr_version]).to eql("4.0.30319.34014") + expect(plugin.languages[:powershell][:build_version]).to eql("6.3.9600.16394") + expect(plugin.languages[:powershell][:compatible_versions]).to eql(["1.0", "2.0", "3.0", "4.0"]) + expect(plugin.languages[:powershell][:remoting_protocol_version]).to eql("2.2") end - it "should not set the languages[:powershell] tree up if powershell command fails" do + it "does not set the languages[:powershell] tree up if powershell command fails" do error_output = <<END 'powershell.exe' is not recognized as an internal or external command, operable program or batch file. END - allow(@plugin).to receive(:shell_out).with(anything).and_return(mock_shell_out(1, error_output, "")) - @plugin.run - expect(@plugin.languages).not_to have_key(:powershell) + allow(plugin).to receive(:shell_out).with(anything).and_return(mock_shell_out(1, error_output, "")) + plugin.run + expect(plugin.languages).not_to have_key(:powershell) end end diff --git a/spec/unit/plugins/python_spec.rb b/spec/unit/plugins/python_spec.rb index 87fd5c14..8e9fb478 100644 --- a/spec/unit/plugins/python_spec.rb +++ b/spec/unit/plugins/python_spec.rb @@ -31,11 +31,11 @@ describe Ohai::System, "plugin python" do plugin end - it "should get the python version from printing sys.version and sys.platform" do + it "gets the python version from printing sys.version and sys.platform" do plugin.run end - it "should set languages[:python][:version]" do + it "sets languages[:python][:version]" do plugin.run expect(plugin.languages[:python][:version]).to eql("2.5.2") end @@ -43,7 +43,7 @@ describe Ohai::System, "plugin python" do context "when the python command fails" do let(:retval) { 1 } - it "should not set the languages[:python] tree up" do + it "does not set the languages[:python] tree up" do plugin.run expect(plugin.languages).not_to have_key(:python) end |