【问题标题】:ruby-debug and cucumber红宝石调试和黄瓜
【发布时间】:2011-02-04 13:11:50
【问题描述】:

我在 cucumber 中有一个失败的场景,我想使用 ruby​​-debug 调试我的 rails 控制器。但是,如果我将“调试器”添加到我想要中断的位置,它就不会停止。

我尝试将 ruby​​-debug 和 ruby​​gems 的 require 添加到 features/support/env.rb 但是它告诉我它无法加载 ruby​​-debug,尽管 ruby​​-debug 在 gem 列表中并且我可以将其加载到 irb 中。

那么...我应该怎么做才能让它工作?

谢谢!

【问题讨论】:

  • 你使用的是什么版本的 Ruby?
  • ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32] 在 Windows Vista 上

标签: ruby-on-rails cucumber ruby-debug


【解决方案1】:

我今天遇到了同样的问题,我想通了。这是我的博客文章,解释了我让它工作的两种不同方式:

http://lostechies.com/derickbailey/2011/06/29/debugging-cucumber-tests-with-ruby-debug/

您可能只需将require "ruby-debug" 添加到您的 features/support/env.rb 文件即可使其正常工作。

【讨论】:

    【解决方案2】:

    尝试添加breakpoint 而不是debugger

    应该可以的

    【讨论】:

      【解决方案3】:

      这里的关键肯定是首先加载ruby-debug

      如果您遇到无法加载 gem 的问题,并且 gem 肯定在您的 Gemfile 中列出,请运行 cucumber,如下所示:

      捆绑执行黄瓜...

      这对于 bundler 来说通常是必要的。

      【讨论】:

        【解决方案4】:

        对于现代 Ruby 版本的调试器(使用 binding.pry),我建议使用以下内容创建一个文件 features/support/debugging.rb,然后调用 cucumber 并将环境变量设置为调试:

        # `LAUNCHY=1 cucumber` to open page on failure
        After do |scenario|
          # rubocop:disable Lint/Debugger
          save_and_open_page if scenario.failed? && ENV['LAUNCHY']
          # rubocop:enable Lint/Debugger
        end
        
        # `FAST=1 cucumber` to stop on first failure
        After do |scenario|
          Cucumber.wants_to_quit = ENV['FAST'] && scenario.failed?
        end
        
        # `DEBUG=1 cucumber` to drop into debugger
        Before do |scenario|
          next unless ENV['DEBUG']
          # rubocop:disable Lint/Debugger
          puts "Debugging scenario: #{scenario.title}"
          binding.pry
          # rubocop:enable Lint/Debugger
        end
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-03-22
          • 2013-06-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多