Start ruby debugger if rspec test fails

前端 未结 6 1787
谎友^
谎友^ 2021-02-05 05:11

Often, when a test fails, I spend quite sometime trying to figure out the what caused it to fail. It\'d be useful if RSpec could kick off a Ruby debugger when the test fails, so

6条回答
  •  后悔当初
    2021-02-05 05:35

    You won't get access to local variables (easily) without debugger being in scope of the block, however RSpec provides you with around hooks which let's you do this:

    config.around(:each) do |example|
      result = example.run
      debugger if result.is_a?(Exception)
      puts "Debugging enabled"
    end
    

    You then have access to @ivars and subject / let(:var) contents at this point.

提交回复
热议问题