Class: HeapScope::RSpecMatchers::GrowHeapByMoreThan
- Inherits:
-
Object
- Object
- HeapScope::RSpecMatchers::GrowHeapByMoreThan
- Defined in:
- lib/heapscope/rspec.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(bytes) ⇒ GrowHeapByMoreThan
constructor
A new instance of GrowHeapByMoreThan.
- #matches?(proc) ⇒ Boolean
- #supports_block_expectations? ⇒ Boolean
Constructor Details
#initialize(bytes) ⇒ GrowHeapByMoreThan
Returns a new instance of GrowHeapByMoreThan.
59 60 61 62 |
# File 'lib/heapscope/rspec.rb', line 59 def initialize(bytes) @bytes = bytes @report = nil end |
Instance Method Details
#failure_message ⇒ Object
70 71 72 |
# File 'lib/heapscope/rspec.rb', line 70 def "expected heap growth > #{@bytes}, got #{@actual}" end |
#failure_message_when_negated ⇒ Object
74 75 76 77 |
# File 'lib/heapscope/rspec.rb', line 74 def suspects = Array(@report&.suspects).first(5).map { |s| "#{s[:name]}(+#{s[:delta_count]})" }.join(", ") "expected heap not to grow by more than #{@bytes}, got #{@actual}. Suspects: #{suspects}" end |
#matches?(proc) ⇒ Boolean
64 65 66 67 68 |
# File 'lib/heapscope/rspec.rb', line 64 def matches?(proc) @report = HeapScope.measure(force_gc: true) { proc.call } @actual = @report.diff&.heap_bytes_estimate_delta.to_i @actual > @bytes end |
#supports_block_expectations? ⇒ Boolean
79 80 81 |
# File 'lib/heapscope/rspec.rb', line 79 def supports_block_expectations? true end |