How to debug a plugin or gem using ruby-debug gem, where the part I wanted to debug started from test scripts?
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.
精彩评论