Panasonic Youth rob sanheim writes about software, business, ruby, music, stuff and things



Posted
14 June 2006 @ 1pm

Tagged
Rails, Ruby, TDD

Discuss

Testing the ApplicationController in Rails

Not sure why this test case isn't generated right away, but here it is:

require File.dirname(__FILE__) + '/../test_helper'
require 'application'

# Re-raise errors caught by the controller.
class ApplicationController; def rescue_action(e) raise e end; end

class ApplicationControllerTest <Test::Unit::TestCase
 
  def setup
    @controller = ApplicationController.new
  end
 
# your test here
  def test_truth
    assert true
  end
end


2 Comments

Posted by
Fabio
8 July 2006 @ 8pm

Hello,

I agree that this should be generated automatically. I’ve got the above, but my test is giving me a method_missing for the method I want to test . . . Like it doesn’t see ApplicationController at all, although it does not compain at the require line, so it is getting it. Any ideas?


Posted by
Rob
10 July 2006 @ 9pm

You have to test a bit differently, since the app controller is really just a base class that your other controllers extend. Try calling your test class like this:

def test_something
assert @controller.some_method, "error message here..."
end


Leave a Comment

Users Don’t Know (and Don’t Care) What RSS (or Ajax, or CSS…) Is Rails Conf 2006, this blog, and biking