如何在Rails功能测试中调用调试器?

Jay*_*itt 9 debugging unit-testing ruby-on-rails ruby-on-rails-3

使用Rails 3,Ruby 1.9和Test :: Unit,在功能测试中调用调试器的正确方法是什么?我尝试添加"调试器",然后运行rake:test:functionals:

class AdminControllerTest < ActionController::TestCase
    test "should get index" do
        debugger
        get :index
        assert_redirected_to welcome_url
    end
end
Run Code Online (Sandbox Code Playgroud)

但Ruby似乎忽略了对调试器的调用(测试继续进行并正常运行).如果我尝试直接运行测试:

ruby -r debug test/functional/admin_controller_test.rb
Run Code Online (Sandbox Code Playgroud)

然后Ruby找不到test_helper.rb.如果按照以下答案,我运行:

ruby -I "lib:test" test/functional/admin_controller_test.rb
Run Code Online (Sandbox Code Playgroud)

然后它找到test_helper但是再次运行测试完成而不调用调试器.我的Gemfile确实有:

gem 'ruby-debug19', :require => 'ruby-debug', :group => :development
Run Code Online (Sandbox Code Playgroud)

njo*_*den 9

我总是能够使用以下方式调试测试:

ruby -I"lib:test" test/functional/admin_controller_test.rb
Run Code Online (Sandbox Code Playgroud)

我的.rdebugrc文件中有以下内容,如果它有帮助:

set autolist
set autoeval
set autoreload
set forcestep
Run Code Online (Sandbox Code Playgroud)

  • bing bing bing!我只在:开发组中使用了ruby-debug19. (6认同)