Start ruby debugger if rspec test fails

前端 未结 6 1790
谎友^
谎友^ 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:25

    I like @jon-rowe's solution (no additional gems needed) with a slight edit: I really don't care about other errors as much as RSpec::Expectations::ExpectationNotMetError.

      config.around(:each) do |example|
        example.run.tap do |result|
          debugger if result.is_a?(RSpec::Expectations::ExpectationNotMetError)
        end
      end
    

提交回复
热议问题