Class: HeapScope::RSpecMatchers::RetainLessThan
- Inherits:
-
Object
- Object
- HeapScope::RSpecMatchers::RetainLessThan
- Defined in:
- lib/heapscope/rspec.rb
Instance Method Summary collapse
- #bytes ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(limit) ⇒ RetainLessThan
constructor
A new instance of RetainLessThan.
- #matches?(proc) ⇒ Boolean
- #objects ⇒ Object
- #of(klass) ⇒ Object
- #supports_block_expectations? ⇒ Boolean
Constructor Details
#initialize(limit) ⇒ RetainLessThan
Returns a new instance of RetainLessThan.
9 10 11 12 13 14 |
# File 'lib/heapscope/rspec.rb', line 9 def initialize(limit) @limit = limit @unit = :objects @klass = nil @report = nil end |
Instance Method Details
#bytes ⇒ Object
21 22 23 24 |
# File 'lib/heapscope/rspec.rb', line 21 def bytes @unit = :bytes self end |
#failure_message ⇒ Object
44 45 46 47 |
# File 'lib/heapscope/rspec.rb', line 44 def suspects = Array(@report&.suspects).first(5).map { |s| "#{s[:name]}(+#{s[:delta_count]})" }.join(", ") "expected retained #{@unit}#{@klass ? " of #{@klass}" : ""} < #{@limit}, got #{@actual}. Suspects: #{suspects}" end |
#failure_message_when_negated ⇒ Object
49 50 51 |
# File 'lib/heapscope/rspec.rb', line 49 def "expected retained #{@unit} >= #{@limit}, got #{@actual}" end |
#matches?(proc) ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/heapscope/rspec.rb', line 31 def matches?(proc) @report = HeapScope.measure(force_gc: true) { proc.call } @actual = if @klass @unit == :bytes ? @report.retained_bytes_for(@klass) : @report.retained_count_for(@klass) elsif @unit == :bytes @report.diff&.heap_bytes_estimate_delta.to_i else @report.diff&.surviving_estimate.to_i end @actual < @limit end |
#objects ⇒ Object
16 17 18 19 |
# File 'lib/heapscope/rspec.rb', line 16 def objects @unit = :objects self end |
#of(klass) ⇒ Object
26 27 28 29 |
# File 'lib/heapscope/rspec.rb', line 26 def of(klass) @klass = klass self end |
#supports_block_expectations? ⇒ Boolean
53 54 55 |
# File 'lib/heapscope/rspec.rb', line 53 def supports_block_expectations? true end |