Module: Util

Includes:
DerivedConstants
Defined in:
lib/turtle_hunter/util.rb

Constant Summary

Constants included from DerivedConstants

DerivedConstants::CONTROLLER_THRESHOLD, DerivedConstants::ELSE_THRESHOLD, DerivedConstants::FEATURE_THRESHOLD, DerivedConstants::LENIENCE_FLAG, DerivedConstants::LENIENCE_LEVEL, DerivedConstants::MODEL_THRESHOLD, DerivedConstants::SKIP_FLAG

Class Method Summary collapse

Class Method Details

.guard_against_slow_spec(example) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/turtle_hunter/util.rb', line 6

def self.guard_against_slow_spec(example)
  @example = example
  return unless passes_preconditions?

  fail_after = set_defaults
  started_at = example.[:execution_result].started_at
  now = Time.now
  runtime = (now - started_at) * 1000

  if runtime > fail_after
    message = "    Expected spec to run within \#{fail_after} milliseconds but it took \#{runtime} milliseconds.\n    Lenience was set to `\#{lenience?}`\n\n    If you want to disable turtle_hunter for this run, set `ENV[\"FAIL_SLOW\"]=false` while you run specs.\n\n    If you want to skip turtle_hunter for this spec, add `\#{SKIP_FLAG}: true` to the example.\n    HEREDOC\n    fail message\n  end\nend\n"