0

I am in a situation where I need to step through the controller method when I run a functional test. I use ruby-debug to debug through my application. My app is a rails 3.1 app which uses ruby-1.8.7 . I can debug my code by using

rails server --debugger OR rails console --debugger

I can also stop the code by inserting "debugger" in a model and run it's respective unit test.

But I am not able to do the same thing with the controllers. That is I am not able to stop the code by inserting "debugger" in the methods of the controller and run it's respective functional test.

Has anyone faced this issue before?

Also I use devise for authentication so I need to add the following lines to my test_helper

class ActionController::TestCase
  include Devise::TestHelpers

  def login_user
    @request.env["devise.mapping"] = Devise.mappings[:user]
    @user.confirm!
    sign_in @user
  end
end

Not sure I that is going to effect the debugger in anyway.

vishal
  • 279
  • 4
  • 14
  • there is the ruby-debugger command for running commands with the debugger: http://stackoverflow.com/questions/2663912/rails-debugging-rails-tasks – phoet Jul 19 '12 at 22:20

1 Answers1

3

I was unable to stop at a debugger inserted in my controller method when I ran the functional tests because I was hitting a before_filter

vishal
  • 279
  • 4
  • 14
  • do you have any explanation why hitting a before_filter avoids debugging the controllers when testing? – elhoyos Aug 02 '12 at 16:05
  • If I had a before filter like authenticated_user and in my tests and I dont setup an authenticated_user and try to hit the debugger in a controller method. If the code in the before filter is written such that in absence of an authenticated user redirect to the home page. So when I run my test without creating the authenticated user I am taken to another method in the home page controller rather that the intended method. This way the code never hits the debugger. – vishal Aug 03 '12 at 20:19