Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I invoke the debugger in a Rails functional test?

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
like image 774
Jay Levitt Avatar asked Apr 12 '11 15:04

Jay Levitt


People also ask

How do you run a Minitest in rails?

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.

How do you use Byebug in Ruby?

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.

How do I add a breakpoint in rails?

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.


1 Answers

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
like image 166
njorden Avatar answered Sep 16 '22 20:09

njorden