Start ruby debugger if rspec test fails

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

    Use pry-rescue, it's the spiritual successor to plymouth:

    From the Readme:

    If you're using RSpec or respec, you can open a pry session on every test failure using rescue rspec or rescue respec:

    $ rescue rspec
    From: /home/conrad/0/ruby/pry-rescue/examples/example_spec.rb @ line 9 :
    
         6:
         7: describe "Float" do
         8:   it "should be able to add" do
     =>  9:     (0.1 + 0.2).should == 0.3
        10:   end
        11: end
    
    RSpec::Expectations::ExpectationNotMetError: expected: 0.3
         got: 0.30000000000000004 (using ==)
    [1] pry(main)>
    

提交回复
热议问题