How do i get rid of @controller is nil error in my tests

when you inherit from ActionController::TestCase it infers the controller name from the test name if they do not match you have to use the setup part of test to set it.

So if you have

class PostsControllerTest < ActionController::TestCase
  def test_index
    #assert something
  end
end

Then @controller is auto instantiated to PostsController, however, if this were not the case and you had a different name you would need a setup as such

class SomeTest < ActionController::TestCase
  def setup
    @controller = PostController.new
  end
end

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)