Class: HeapScope::RSpecMatchers::GrowHeapByMoreThan

Inherits:
Object
  • Object
show all
Defined in:
lib/heapscope/rspec.rb

Instance Method Summary collapse

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_messageObject



70
71
72
# File 'lib/heapscope/rspec.rb', line 70

def failure_message
  "expected heap growth > #{@bytes}, got #{@actual}"
end

#failure_message_when_negatedObject



74
75
76
77
# File 'lib/heapscope/rspec.rb', line 74

def failure_message_when_negated
  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

Returns:

  • (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

Returns:

  • (Boolean)


79
80
81
# File 'lib/heapscope/rspec.rb', line 79

def supports_block_expectations?
  true
end