From 02a5801d7edf575a42fd75d0b29b49f212fa443f Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 25 Mar 2014 14:46:06 -0700 Subject: [PATCH] Fix count_via_win32 on non-win32 When rake does not recognize your platform in CpuCounter it tries all known methods. If your platform is not a windows platform you will not have win32ole so a LoadError was raised but not rescued. Now the LoadError is rescued so rake can try alternate mechanisms. See #261 --- lib/rake/cpu_counter.rb | 2 +- test/test_rake_cpu_counter.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/rake/cpu_counter.rb b/lib/rake/cpu_counter.rb index 0afb0e34b..6cabbf732 100644 --- a/lib/rake/cpu_counter.rb +++ b/lib/rake/cpu_counter.rb @@ -51,7 +51,7 @@ def count_via_win32 wmi = WIN32OLE.connect("winmgmts://") cpu = wmi.ExecQuery("select NumberOfCores from Win32_Processor") # TODO count hyper-threaded in this cpu.to_enum.first.NumberOfCores - rescue StandardError + rescue StandardError, LoadError nil end diff --git a/test/test_rake_cpu_counter.rb b/test/test_rake_cpu_counter.rb index cb5c1a0f2..d9f8b2073 100644 --- a/test/test_rake_cpu_counter.rb +++ b/test/test_rake_cpu_counter.rb @@ -8,6 +8,14 @@ def setup @cpu_counter = Rake::CpuCounter.new end + def test_count_via_win32 + if Rake::Win32.windows? then + assert_kind_of Numeric, @cpu_counter.count_via_win32 + else + assert_nil @cpu_counter.count_via_win32 + end + end + def test_in_path_command with_ruby_in_path do |ruby| assert_equal ruby, @cpu_counter.in_path_command(ruby)