Sha256: 4977d3baf2298ae6f21683df414d5388559557d48472ad23aa8ed69fd15fa325

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

require "rspec/debug/version"

return unless ['1', 'true'].include?(ENV['RSPEC_DEBUG'])

# start debug session
require 'debug/session'
DEBUGGER__::start no_sigint_hook: true, nonstop: true

module RSpec
  module Core
    class Example
      module DebugAtStop
        def initialize example_group_class, description, user_metadata, example_block=nil
          orig_example_block = example_block

          if example_block
            example_block = Proc.new do
              begin
                postmortem_hook = TracePoint.new(:raise){|tp|
                  exc = tp.raised_exception
                  frames = DEBUGGER__.capture_frames(nil)
                  frames.delete_if{|e| /(exe|bin|lib)\/rspec/ =~ e.path}
                  exc.instance_variable_set(:@__debugger_postmortem_frames, frames)
                }

                postmortem_hook.enable
                begin
                  self.instance_eval(&orig_example_block)
                ensure
                  postmortem_hook.disable
                end

              rescue Exception => e
                STDERR.puts "Failure:"
                STDERR.puts e.message
                DEBUGGER__::SESSION.enter_postmortem_session e
                raise
              end
            end # Proc.new
          end

          super
        end
      end
      prepend DebugAtStop
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-debug-0.1.0 lib/rspec/debug.rb