2011-04-12 71 views
9

在Rails 3,Ruby 1.9和Test :: Unit中,在功能測試中調用調試器的正確方法是什麼?我已經嘗試添加「調試」,然後運行耙:測試:泛函:如何在Rails功能測試中調用調試器?

class AdminControllerTest < ActionController::TestCase 
    test "should get index" do 
     debugger 
     get :index 
     assert_redirected_to welcome_url 
    end 
end 

但是Ruby似乎忽視了調用調試器(測試繼續並正常運行)。如果我嘗試直接運行測試:

ruby -r debug test/functional/admin_controller_test.rb 

然後Ruby找不到test_helper.rb。如果按照下面的答案,我運行:

ruby -I "lib:test" test/functional/admin_controller_test.rb 

然後它找到test_helper,但再次運行測試完成而無需調用調試器。我的Gemfile確實有:

gem 'ruby-debug19', :require => 'ruby-debug', :group => :development 

回答

9

只使用我一直能夠調試測試:

ruby -I"lib:test" test/functional/admin_controller_test.rb 

我有我的.rdebugrc文件下面,如果它可以幫助:

set autolist 
set autoeval 
set autoreload 
set forcestep 
+0

不,這不是推出爲我調試;即使在將這些行添加到.rdebugrc之後,測試仍會完成。 – 2011-04-12 15:44:13

+1

但是你可以調試你的應用程序,而不是測試?你的「gem'ruby-debug19',:require =>'ruby-debug'」包含在你的測試組中,還有:development? – njorden 2011-04-12 15:55:09

+6

冰冰冰冰!我只在開發組中擁有ruby-debug19。 – 2011-04-12 16:07:29

3

您將需要ruby-debug19寶石。

+0

我已經做了;編輯問題以表明這一點。 – 2011-04-12 16:02:34

1

我有這個相同的問題,並通過添加'調試器'到我的Gemfile中的測試組來解決它。

的Gemfile:

group :test do 
    gem "debugger" 
end 

命令:

bundle exec ruby -Itest test/unit/user_test.rb -n test_the_truth