Class: ErgomentumRspec::Matchers::Performance::AllocateObjects

Inherits:
Object
  • Object
show all
Defined in:
lib/ergomentum_rspec/matchers/performance/allocate_objects.rb

Instance Method Summary collapse

Instance Method Details

#descriptionObject



88
89
90
# File 'lib/ergomentum_rspec/matchers/performance/allocate_objects.rb', line 88

def description
  "allocates number of objects"
end

#exactly(expected) ⇒ Object



33
34
35
36
37
38
# File 'lib/ergomentum_rspec/matchers/performance/allocate_objects.rb', line 33

def exactly(expected)
  @expected = expected
  @compare = proc { @trace.new_allocations.size == @expected }
  @message = ""
  self
end

#failure_messageObject



76
77
78
79
80
# File 'lib/ergomentum_rspec/matchers/performance/allocate_objects.rb', line 76

def failure_message
  "expected #{@message}#{@expected} objects to be allocated; "\
    "got #{@trace.new_allocations.size}:\n\n"\
    "#{@trace.allocations(alias_paths: true).group_by(:sourcefile, :sourceline, :class).to_text}"
end

#failure_message_when_negatedObject



82
83
84
85
86
# File 'lib/ergomentum_rspec/matchers/performance/allocate_objects.rb', line 82

def failure_message_when_negated
  "expected not #{@message}#{@expected} objects to be allocated; "\
    "got #{@trace.new_allocations.size}:\n\n"\
    "#{@trace.allocations(alias_paths: true).group_by(:sourcefile, :sourceline, :class).to_text}"
end

#less_than(expected) ⇒ Object



40
41
42
43
44
45
# File 'lib/ergomentum_rspec/matchers/performance/allocate_objects.rb', line 40

def less_than(expected)
  @expected = expected
  @compare = proc { @trace.new_allocations.size < @expected }
  @message = "less than "
  self
end

#matches?(*actual, &block) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ergomentum_rspec/matchers/performance/allocate_objects.rb', line 21

def matches?(*actual, &block)
  @trace = if block
             AllocationStats.trace(&block)
           elsif actual.first.is_a?(Proc)
             AllocationStats.trace(&actual.first)
           else
             actual.first
           end
  @compare || raise(IncompleteExpectationError)
  @compare.call
end

#max(expected) ⇒ Object



54
55
56
57
58
59
# File 'lib/ergomentum_rspec/matchers/performance/allocate_objects.rb', line 54

def max(expected)
  @expected = expected
  @compare = proc { @trace.new_allocations.size <= @expected }
  @message = "max "
  self
end

#min(expected) ⇒ Object



61
62
63
64
65
66
# File 'lib/ergomentum_rspec/matchers/performance/allocate_objects.rb', line 61

def min(expected)
  @expected = expected
  @compare = proc { @trace.new_allocations.size >= @expected }
  @message = "min "
  self
end

#more_than(expected) ⇒ Object



47
48
49
50
51
52
# File 'lib/ergomentum_rspec/matchers/performance/allocate_objects.rb', line 47

def more_than(expected)
  @expected = expected
  @compare = proc { @trace.new_allocations.size > @expected }
  @message = "more than "
  self
end

#objectObject



68
69
70
# File 'lib/ergomentum_rspec/matchers/performance/allocate_objects.rb', line 68

def object
  self
end

#objectsObject



72
73
74
# File 'lib/ergomentum_rspec/matchers/performance/allocate_objects.rb', line 72

def objects
  self
end

#supports_block_expectations?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/ergomentum_rspec/matchers/performance/allocate_objects.rb', line 17

def supports_block_expectations?
  true
end