Browse files

Fixed spec for system_profiler

  • Loading branch information...
1 parent 5da36d2 commit fb1c5ab1368b88be6db2ab50afea2339599c0851 Paul Mooring committed with btm Dec 6, 2012
Showing with 17 additions and 12 deletions.
  1. +5 −1 Gemfile
  2. +1 −4 lib/ohai/plugins/darwin/system_profiler.rb
  3. +11 −7 spec/ohai/plugins/darwin/system_profiler_spec.rb
View
6 Gemfile
@@ -2,5 +2,9 @@ source :rubygems
gemspec
-gem "sigar", :group => :development, :platform => "ruby"
+group :development do
+ gem "sigar", :platform => "ruby"
+ gem 'plist'
+end
+
View
5 lib/ohai/plugins/darwin/system_profiler.rb
@@ -15,14 +15,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-
provides "system_profile"
-begin
+begin
require 'plist'
system_profile Array.new
-
detail_level = {
'mini' => [
"SPParallelATAData",
@@ -66,7 +64,6 @@
end
system_profile.sort_by! { |h| h['_dataType'] }
-
rescue LoadError => e
Ohai::Log.debug("Can't load gem: #{e})")
end
View
18 spec/ohai/plugins/darwin/system_profiler_spec.rb
@@ -1,6 +1,6 @@
#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
+# Author:: Paul Mooring (<paul@opscode.com>)
+# Copyright:: Copyright (c) 2012 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,11 +28,15 @@
end
it "should return the right serial number" do
- @ohai.stub!(:popen4).with("system_profiler -xml -detailLevel full SPHardwareDataType").and_yield(nil, nil, SystemProfilerOutput::Full, nil)
- @ohai.stub!(:popen4).with("system_profiler -xml -detailLevel mini").and_yield(nil, nil, SystemProfilerOutput::Mini, nil)
+ mini_cmd = "system_profiler -xml -detailLevel mini SPParallelATAData SPAudioData SPBluetoothData"
+ mini_cmd += " SPCardReaderData SPDiagnosticsData SPDiscBurningData SPEthernetData SPFibreChannelData"
+ mini_cmd += " SPFireWireData SPDisplaysData SPHardwareRAIDData SPMemoryData SPModemData SPNetworkData"
+ mini_cmd += " SPPCIData SPParallelSCSIData SPPrintersSoftwareData SPPrintersData SPSASData SPSerialATAData"
+ mini_cmd += " SPSoftwareData SPThunderboltData SPUSBData SPWWANData SPAirPortData"
+ full_cmd = "system_profiler -xml -detailLevel full SPHardwareDataType"
+ @ohai.stub!(:popen4).with(full_cmd).and_yield(nil, StringIO.new, StringIO.new(SystemProfilerOutput::Full), nil)
+ @ohai.stub!(:popen4).with(mini_cmd).and_yield(nil, StringIO.new, StringIO.new(SystemProfilerOutput::Mini), nil)
@ohai._require_plugin("darwin::system_profiler")
- require 'pp'
- pp @ohai['system_profile']
- @ohai['system_profile'][10]["_items"][0]["serial_number"].should == 'ABCDEFG12345'
+ @ohai['system_profile'][18]["_items"][0]["serial_number"].should == 'ABCDEFG12345'
end
end

0 comments on commit fb1c5ab

Please sign in to comment.