Module: RSpec::Debugging::DebugIt

Defined in:
lib/rspec/debugging/debug_it.rb

Constant Summary collapse

ENABLED =
['1', 'true'].include?(ENV['RSPEC_DEBUGGING'])

Instance Method Summary collapse

Instance Method Details

#initialize(example_group_class, description, user_metadata, example_block = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rspec/debugging/debug_it.rb', line 8

def initialize(example_group_class, description, , example_block=nil)
  return super unless [:debug] || ENABLED

  if example_block
    orig_example_block = example_block

    example_block = Proc.new do
      e = DEBUGGER__::SESSION.capture_exception_frames /(exe|bin|lib)\/rspec/ do
        instance_exec(&orig_example_block)
      end

      if e
        STDERR.puts <<~MSG

        Error:
        #{e.message}

        MSG

        DEBUGGER__::SESSION.enter_postmortem_session e
        raise e
      end
    end # Proc.new
  elsif [:debug] && [:skip] == RSpec::Core::Pending::NOT_YET_IMPLEMENTED
    # called with no block
    .delete(:skip)

    file, line = caller[2].split(":")

    example_block = Proc.new do
      STDERR.puts <<~MSG
      debugging: #{file}:#{line}

      MSG

      debugger
    end
  end

  super
end