Class: PerfSpec::WhySoLong

Inherits:
Object
  • Object
show all
Defined in:
lib/perf_spec/why_so_long.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected_time) ⇒ WhySoLong



8
9
10
# File 'lib/perf_spec/why_so_long.rb', line 8

def initialize(expected_time)
  @expected_time = expected_time
end

Instance Attribute Details

#bullet_enable_statObject (readonly)

Returns the value of attribute bullet_enable_stat.



6
7
8
# File 'lib/perf_spec/why_so_long.rb', line 6

def bullet_enable_stat
  @bullet_enable_stat
end

#bullet_warningsObject (readonly)

Returns the value of attribute bullet_warnings.



6
7
8
# File 'lib/perf_spec/why_so_long.rb', line 6

def bullet_warnings
  @bullet_warnings
end

#check_resultObject (readonly)

Returns the value of attribute check_result.



6
7
8
# File 'lib/perf_spec/why_so_long.rb', line 6

def check_result
  @check_result
end

#expected_timeObject (readonly)

Returns the value of attribute expected_time.



6
7
8
# File 'lib/perf_spec/why_so_long.rb', line 6

def expected_time
  @expected_time
end

#meta_request_idObject (readonly)

Returns the value of attribute meta_request_id.



6
7
8
# File 'lib/perf_spec/why_so_long.rb', line 6

def meta_request_id
  @meta_request_id
end

#real_timeObject (readonly)

Returns the value of attribute real_time.



6
7
8
# File 'lib/perf_spec/why_so_long.rb', line 6

def real_time
  @real_time
end

Instance Method Details

#check(&block) ⇒ Object



12
13
14
15
16
# File 'lib/perf_spec/why_so_long.rb', line 12

def check(&block)
  @real_time = Benchmark.realtime do
    @check_result = block.call
  end
end

#failure_message(_actual, matcher) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/perf_spec/why_so_long.rb', line 22

def failure_message(_actual, matcher)
  @meta_request_id = extract_meta_request_id(matcher)
  return default_failure_message unless meta_request_id
  [
    default_failure_message,
    "\nTakes controller: ",
    META_REQUEST_KEYS.map { |key| "#{key}: #{duration_sum(meta_request_output, key)}" }.join(', '),
    "\n",
    meta_request_output.ai(indent: -2)
  ].join('')
end

#success?Boolean



18
19
20
# File 'lib/perf_spec/why_so_long.rb', line 18

def success?
  @success ||= real_time <= expected_time
end