1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
# frozen_string_literal: true
require File.expand_path("../helper", __FILE__)
class TestRakeCpuCounter < Rake::TestCase # :nodoc:
def setup
super
@cpu_counter = Rake::CpuCounter.new
end
def test_count
num = @cpu_counter.count
omit "cannot count CPU" if num == nil
assert_kind_of Numeric, num
assert_operator num, :>=, 1
end
def test_count_with_default_nil
def @cpu_counter.count; nil; end
assert_equal(8, @cpu_counter.count_with_default(8))
assert_equal(4, @cpu_counter.count_with_default)
end
def test_count_with_default_raise
def @cpu_counter.count; raise; end
assert_equal(8, @cpu_counter.count_with_default(8))
assert_equal(4, @cpu_counter.count_with_default)
end
class TestClassMethod < Rake::TestCase # :nodoc:
def setup
super
@klass = Class.new(Rake::CpuCounter)
end
def test_count
@klass.class_eval do
def count; 8; end
end
assert_equal(8, @klass.count)
end
def test_count_nil
counted = false
@klass.class_eval do
define_method(:count) do
counted = true
nil
end
end
assert_equal(4, @klass.count)
assert_equal(true, counted)
end
def test_count_raise
counted = false
@klass.class_eval do
define_method(:count) do
counted = true
raise
end
end
assert_equal(4, @klass.count)
assert_equal(true, counted)
end
end
end
|