如何使用ruby-debug gem来调试插件或gem,其中我想调试的部分是从测试脚本开始的? [英] How to debug a plugin or gem using ruby-debug gem, where the part I wanted to debug started from test scripts?

查看:89
本文介绍了如何使用ruby-debug gem来调试插件或gem,其中我想调试的部分是从测试脚本开始的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有一个名为Authlogic-openid的gem,该插件已过时,不再支持,并且被破坏(如果您知道其他方法,请告诉我)。

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

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

起初它返回

  LoadError:没有这样的文件加载 -  ruby​​-debug 

code>

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

  requireruby-debug

然后我通过安装ruby-debug gem

  gem install ruby​​-debug 

然后我将它添加到environment.rb中
$ b

  config.gem'红宝石- 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] 

所以我在其上键入调试器现在显示为:

 调试器
session_class.controller.params [:open_id_complete]&& session_class.controller.params [:for_model]

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

  DEPRECATION警告:请更新配置/database.yml使用'数据库'而不是'dbfile'。 (在/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从parse_sqlite_config!调用)
加载套件/Volumes/Data/work/ror/user_manager/vendor/gems/authlogic-oid-1.0.4/test/acts_as_authentic_test
已启动
E
已完成0.009325秒。
$ b $ 1)错误:
test_password_not_required_on_create(ActsAsAuthenticTest):


NoMethodError:未定义方法`logger'为true:TrueClass
方法调试器在第6行的debugger.rb中
方法openid_complete?位于第157行的acts_as_authentic.rb中
方法中83行中的acts_as_authentic.rb中的authenticate_with_openid
行中acts_as_authentic.rb中的方法save
方法test_password_not_required_on_create中第16行的acts_as_authentic_test.rb
方法__send__在第62行的setup_and_teardown.rb中
方法在第62行的setup_and_teardown.rb中运行

1个测试,0个断言,0个失败,1个错误

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



红利问题:为什么我会得到弃用警告?如何解决它?



我的database.yml文件如下:

 #MySQL。推荐版本4.1和5.0。 

#安装MySQL驱动程序:
#gem install mysql
#在Mac OS X上:
#sudo gem install mysql - --with-mysql- dir = / usr / local / mysql
#在Mac OS X Leopard上:
#sudo env ARCHFLAGS = - arch i386gem install mysql - --with-mysql-config = / usr / local / mysql / bin / mysql_config
#这将ARCHFLAGS环境变量设置为本地架构
#在Windows上:
#gem install mysql
#选择win32版本。
#安装MySQL并将其/ bin目录放在您的路径中。

#并确保使用新式密码哈希:
#http://dev.mysql.com/doc/refman/5.0/en/old-client.html
开发:
适配器:mysql
编码:utf8
reconnect:false
数据库:user_manager_development
池:5
用户名:root
密码:oisadj
socket:/tmp/mysql.sock

#警告:定义为test的数据库将被删除,
#从开发数据库中重新生成当你运行耙。
#不要将此db设置为与开发或生产相同。
test:
适配器:mysql
编码:utf8
reconnect:false
数据库:user_manager_test
池:5
用户名:root
密码:oisadj
套接字:/tmp/mysql.sock

制作:
适配器:mysql
编码:utf8
重新连接:false
database:user_manager_production
pool:5
username:root
password:
socket:/tmp/mysql.sock

谢谢! 解决方案

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



从Rails的README文件:


使用--debugger启动Mongrel或
Webrick服务器时,可通过调试器命令获得调试器支持。这意味着您可以在代码中的任意位置
跳出执行,调查并更改模型,然后继续执行!
您需要安装 ruby​​-debug 才能运行服务器处于调试模式。使用gem,使用'gem install ruby​​-debug'。







关于弃用警告。


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


看来你使用SQLite。您只需将 config / database.yml 中的 dbfile 行替换为数据库并且警告应该消失。

For example I have this gem called Authlogic-openid, that plugin is outdated, no longer supported, and broken (let me know if you know any alternative by the way).

I wanted to make sure the test runs by keying ctrl+R on vendor/gems/authlogic-oid-1.0.4/test/acts_as_authentic_test.rb

[Please do not attempt to try my steps below, the gem itself was already broken apart so I had to earlier fix up some paths and required libraries... just imagine them in your head]

At first it returned

LoadError: no such file to load — ruby-debug

So I commented the line #3 in test_helper.rb, one that reads:

require "ruby-debug"

then I installed ruby-debug gem by

gem install ruby-debug

Then I added this into environment.rb

  config.gem 'ruby-debug'

Question #1: Are my steps above correct to start my Gem debugging quest?

Alright, so now the line I wanted to debug is in vendor/gems/authlogic-oid-1.0.4/lib/authlogic_openid/acts_as_authentic.rb line #157 (or around it) which reads:

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

So I typed "debugger" on top of it, it now reads:

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

Then when I pressed ctrl + R again on vendor/gems/authlogic-oid-1.0.4/test/acts_as_authentic_test.rb, I got this output:

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

Question #2: Are my steps correct to debug the code? Why did I get the error undefined method 'logger'?

Bonus Question: Why do I get that deprecation warning? How to fix it?

my database.yml file as follows:

# 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

Thank you!

解决方案

Try to run your testing server with the --debugger flag.

From the Rails README file:

Debugger support is available through the debugger command when you start your Mongrel or Webrick server with --debugger. This means that you can break out of execution at any point in the code, investigate and change the model, AND then resume execution! You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'.


Regarding the deprecation warning.

DEPRECATION WARNING: Please update config/database.yml to use 'database' instead of 'dbfile'.

It seems you use SQLite. You just need to replace the dbfile line in your config/database.yml with the database and the warning should gone.

这篇关于如何使用ruby-debug gem来调试插件或gem,其中我想调试的部分是从测试脚本开始的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆