Module: Minitest::Memory
- Defined in:
- lib/minitest/memory.rb,
lib/minitest/memory/version.rb
Overview
Version information for minitest-memory.
Defined Under Namespace
Classes: AllocationCounter
Constant Summary collapse
- VERSION =
Current version of minitest-memory.
"1.0.0".freeze
Instance Method Summary collapse
-
#assert_allocations(limits) ⇒ Object
Fails if any class in
limitsexceeds its allocation count within a block.
Instance Method Details
#assert_allocations(limits) ⇒ Object
Fails if any class in limits exceeds its allocation count within a block. limits is a Hash mapping classes to maximum allowed allocations. Eg:
assert_allocations(String => 1) { "hello" }
50 51 52 53 54 55 56 57 58 |
# File 'lib/minitest/memory.rb', line 50 def assert_allocations(limits, &) actual = AllocationCounter.count(&) limits.each do |klass, max_count| count = actual[klass] msg = "Expected at most #{max_count} #{klass} allocations, got #{count}" assert_operator max_count, :>=, count, msg end end |