How to stop the Rails debugger for the current request

后端 未结 9 1389
既然无缘
既然无缘 2021-02-02 15:50

Say I have a loop in my code that calls the rails debugger a few times

def show
    animals = [\'dog\', \'cat\', \'owl\', \'tiger\']
    for animal in animals
           


        
9条回答
  •  悲&欢浪女
    2021-02-02 16:22

    Putting this here as an alternative since this question showed up first in my own searches. Let's say you have a piece of code that isn't working under a specific circumstance, but works otherwise, and you have a whole slew of tests that exercise this but one specific test that fails. It's a PITA to have to continually type continue into the debug console until you get to the test you really want to debug, so I started using this convention:

    In your code:

    def some_common_function
      debugger if defined? ::ASDF
      # do something
    end
    

    Then in your test:

    should "do this thing that it isn't doing under a specific circumstance" do
      # setup the specific situation
      ::ASDF = true
      # your tests
    end
    

提交回复
热议问题