例如,我有一个名为 Authlogic-openid 的 gem,该插件已过时、不再受支持且已损坏(顺便说一下,如果您知道任何替代方案,请告诉我)。
我想通过在 vendor/gems/authlogic-oid-1.0.4/test/acts_as_authentic_test.rb 上键入 ctrl+R 来确保测试运行
[请不要尝试我下面的步骤,gem 本身已经分解,所以我不得不提前修复一些路径和所需的库......只需在你的脑海中想象它们]
起初它回来了
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”,现在显示为:
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:我调试代码的步骤是否正确?为什么我收到错误 undefined method '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
谢谢!
最佳答案
尝试使用 --debugger
标志运行您的测试服务器。
来自 Rails 自述文件:
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'.
关于弃用警告。
DEPRECATION WARNING: Please update config/database.yml to use 'database' instead of 'dbfile'.
看来您使用的是 SQLite。您只需要用 database
替换 config/database.yml
中的 dbfile
行,警告就会消失。
关于ruby-on-rails - 如何使用 ruby-debug gem 调试插件或 gem,我想调试的部分是从测试脚本开始的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3586386/