Module: RailsMemoryProfiler::TestHelper
- Extended by:
- TestHelper
- Included in:
- TestHelper
- Defined in:
- lib/rails_memory_profiler/test_helper.rb
Instance Method Summary collapse
Instance Method Details
#assert_allocations_below(threshold, &block) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/rails_memory_profiler/test_helper.rb', line 14 def assert_allocations_below(threshold, &block) count = capture_allocations(&block) return if count < threshold = "Expected fewer than #{threshold} allocated objects but got #{count}" error_class = Object.const_defined?(:Minitest) ? Minitest::Assertion : RuntimeError raise error_class, end |
#capture_allocations ⇒ Object
7 8 9 10 11 12 |
# File 'lib/rails_memory_profiler/test_helper.rb', line 7 def capture_allocations GC.start before = GC.stat(:total_allocated_objects) yield GC.stat(:total_allocated_objects) - before end |