RubyMine/IDEA Ruby 调试器无法在捆绑器模式下加载行缓存 gem



IDEA 13(和早期版本,例如 11)中在捆绑器中启动调试器(选中运行目标的捆绑器选项卡中的"在捆绑包上下文中运行脚本"选项) Ruby,我总是得到

/Users/me/.rvm/rubies/ree-1.8.7-2012.02/bin/ruby -e at_exit{sleep(1)};$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/me/.rvm/gems/ree-1.8.7-2012.02/gems/ruby-debug-ide-0.4.22/bin/rdebug-ide --disable-int-handler --port 58100 --dispatcher-port 58101 -- /Users/me/railproj/script/spec --format specdoc spec/**/any_ruby_spec.rb
/Users/me/.rvm/gems/ree-1.8.7-2012.02/gems/ruby-debug-base-0.10.5.rc9/lib/ruby-debug-base.rb:3:in `require': no such file to load -- linecache (LoadError)
    from /Users/me/.rvm/gems/ree-1.8.7-2012.02/gems/ruby-debug-base-0.10.5.rc9/lib/ruby-debug-base.rb:3
    from /Users/me/Library/Application Support/IntelliJIdea13/ruby/rb/gems/debug_preloader.rb:2:in `require'
    from /Users/me/Library/Application Support/IntelliJIdea13/ruby/rb/gems/debug_preloader.rb:2

行缓存 gem 安装正确

$ gem which linecache
/Users/me/.rvm/gems/ree-1.8.7-2012.02/gems/linecache-0.46/lib/linecache.rb

将行缓存放在 Gemfile 中根本没有帮助。

但是在没有捆绑器

的情况下为同一运行目标启动调试器(取消选中"在捆绑包上下文中运行脚本")有效。当然,与捆绑器上下文很容易发生宝石冲突。

如何解决这个问题?

我找到了解决方案/解决方法:只需添加

require 'rubygems'

到 ruby-debug-base.rb 的第一行(确保添加到 RM/Idea 使用的正确行,因为可以有多个版本。

但我仍然不知道为什么它会在没有捆绑器选项的情况下工作。我觉得情况应该正好相反。

对于比 Hacking Bear 提供的更干净的修复程序,避免了对第三方 Gem 的

黑客攻击:

导航到:Run > Edit Configurations

Ruby arguments行前面加上:-r rubygems

从 Ruby 手册页:

   -r library
          Causes Ruby to load the library using require.  It is useful when using -n or -p.

最新更新