With Rails 3, Ruby 1.9, and Test::Unit, what's the right way to invoke the debugger on a functional test? I've tried adding "debugger" and then running rake:test:functionals:
class AdminControllerTest < ActionController::TestCase
test "should get index" do
debugger
get :index
assert_redirected_to welcome_url
end
end
but Ruby seems to ignore the call to debugger (the test goes ahead and runs normally). If I try running the test directly:
ruby -r debug test/functional/admin_controller_test.rb
then Ruby can't find test_helper.rb. If, following the answer below, I run:
ruby -I "lib:test" test/functional/admin_controller_test.rb
then it finds test_helper but again runs the test to completion without invoking the debugger. My Gemfile does have:
gem 'ruby-debug19', :require => 'ruby-debug', :group => :development
To run a Minitest test, the only setup you really need is to require the autorun file at the beginning of a test file: require 'minitest/autorun' . This is good if you'd like to keep the code small. A better way to get started with Minitest is to have Bundler create a template project for you.
wherever you'd like the application to "break" - that is, executing byebug is equivalent to putting a breakpoint in your code. Run the program and use the debugger commands once you reach the breakpoint. near the end. Restart your server.
Set line breakpointsClick the gutter at the executable line of code where you want to set the breakpoint. Alternatively, place the caret at the line and press Ctrl+F8 . To set a temporary line breakpoint, press Ctrl+Alt+Shift+F8 . The breakpoint will be removed from your project right after it is hit.
I've always been able to debug tests using just:
ruby -I"lib:test" test/functional/admin_controller_test.rb
I've got the following in my .rdebugrc file, if it helps:
set autolist
set autoeval
set autoreload
set forcestep
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With