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 "\n        Error:\n        \#{e.message}\n\n        MSG\n\n        DEBUGGER__::SESSION.enter_postmortem_session e\n        raise e\n      end\n    end # Proc.new\n  elsif user_metadata[:debug] && user_metadata[:skip] == RSpec::Core::Pending::NOT_YET_IMPLEMENTED\n    # called with no block\n    user_metadata.delete(:skip)\n\n    file, line = caller[2].split(\":\")\n\n    example_block = Proc.new do\n      STDERR.puts <<~MSG\n      debugging: \#{file}:\#{line}\n\n      MSG\n\n      debugger\n    end\n  end\n\n  super\nend\n"