Module: DeepCover::Tools::ExecuteSample

Defined in:
lib/deep_cover/tools/execute_sample.rb

Instance Method Summary collapse

Instance Method Details

#execute_sample(to_execute) ⇒ Object

Returns true if the code would have continued, false if the rescue was triggered.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/deep_cover/tools/execute_sample.rb', line 6

def execute_sample(to_execute)
  # Disable some annoying warning by ruby. We are testing edge cases, so warnings are to be expected.
  Tools.silence_warnings do
    if to_execute.is_a?(CoveredCode)
      to_execute.execute_code
    else
      to_execute.call
    end
  end
  true
rescue RuntimeError => e
  # In our samples, a simple `raise` doesn't need to be rescued
  # Other exceptions are not rescued
  raise unless e.message.empty?
  false
end