如何使用ruby-debug gem调试插件或gem,我想调试的部分是从测试脚本开始的?

时间:2010-08-27 16:46:33

标签: ruby-on-rails ruby rubygems

例如我有一个名为Authlogic-openid的宝石,该插件已过时,不再受支持和破坏(如果您知道任何替代方式,请告诉我。)

我想通过在vendor / gems / authlogic-oid-1.0.4 / test / acts_as_authentic_test.rb上键入ctrl + R来确保测试运行

[请不要试图尝试我的下面的步骤,宝石本身已经分开,所以我不得不早些时候修复一些路径和需要的库...只是想象它们在你的头脑中]

起初它返回了

LoadError: no such file to load — ruby-debug

所以我评论了test_helper.rb中的第3行,其中一行是:

require "ruby-debug"

然后我通过

安装了ruby-debug gem
gem install ruby-debug

然后我将其添加到environment.rb

  config.gem 'ruby-debug'

问题#1:我的步骤是否正确以启动我的Gem调试任务?

好的,现在我要调试的行是在vendor / gems / authlogic-oid-1.0.4 / lib / authlogic_openid / acts_as_authentic.rb第157行(或它周围),其中包含:

  session_class.controller.params[:open_id_complete] && session_class.controller.params[:for_model]

所以我在它上面键入了“调试器”,它现在显示为:

debugger
session_class.controller.params[:open_id_complete] && session_class.controller.params[:for_model]

然后当我在vendor / gems / authlogic-oid-1.0.4 / test / acts_as_authentic_test.rb上再次按ctrl + R时,我得到了这个输出:

DEPRECATION WARNING: Please update config/database.yml to use 'database' instead of 'dbfile'. (called from parse_sqlite_config! at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/sqlite_adapter.rb:35)
Loaded suite /Volumes/Data/work/ror/user_manager/vendor/gems/authlogic-oid-1.0.4/test/acts_as_authentic_test
Started
E 
Finished in 0.009325 seconds.

  1) Error:
test_password_not_required_on_create(ActsAsAuthenticTest):


NoMethodError: undefined method `logger' for true:TrueClass
method debugger in debugger.rb at line 6
method openid_complete? in acts_as_authentic.rb at line 157
method authenticate_with_openid in acts_as_authentic.rb at line 83
method save in acts_as_authentic.rb at line 73
method test_password_not_required_on_create in acts_as_authentic_test.rb at line 16
method __send__ in setup_and_teardown.rb at line 62
method run in setup_and_teardown.rb at line 62

1 tests, 0 assertions, 0 failures, 1 errors

问题#2:我的步骤是否正确调试代码?为什么我得到错误未定义方法'logger'?

奖金问题:为什么我会收到弃用警告?如何解决?

我的database.yml文件如下:

# MySQL.  Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
#   gem install mysql
# On Mac OS X:
#   sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
# On Mac OS X Leopard:
#   sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
#       This sets the ARCHFLAGS environment variable to your native architecture
# On Windows:
#   gem install mysql
#       Choose the win32 build.
#       Install MySQL and put its /bin directory on your path.
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: user_manager_development
  pool: 5
  username: root
  password: oisadj
  socket: /tmp/mysql.sock

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: user_manager_test
  pool: 5
  username: root
  password: oisadj
  socket: /tmp/mysql.sock

production:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: user_manager_production
  pool: 5
  username: root
  password: 
  socket: /tmp/mysql.sock

谢谢!

1 个答案:

答案 0 :(得分:1)

尝试使用--debugger标志运行测试服务器。

来自Rails README文件:

  

当您启动Mongrel或者调试器时,可以通过调试器命令获得调试器支持   Webrick服务器与--debugger。这意味着您可以随时中断执行   在代码中,调查并更改模型,然后恢复执行!   您需要安装ruby-debug以在调试模式下运行服务器。使用gem,使用'gem install ruby​​-debug'。


关于弃用警告。

  

弃权警告:请更新config / database.yml以使用'database'而不是'dbfile'。

看来你使用的是SQLite。您只需将dbfile中的config/database.yml行替换为database,警告即告消失。