Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
"@controller is nil" error in ActionController::TestCase #5
When using context() inside an ActionController::TestCase, I get the following error:
Here is an example of what my test file looks like:
The error is happening because context() creates a new Test::Unit::TestCase derived class whose name does not contain "ExamplesController", and so Rails becomes confused when it tries to automatically set
Thanks for your consideration.
This comment has been minimized.
This comment has been minimized.Show comment Hide comment
I wrote the following monkeypatch to automate @robgleeson's suggestion of setting
class ActionController::TestCase def self.context *args, &block super *args do setup do # establish the rails controller being tested # https://github.com/citrusbyte/contest/issues/5#issuecomment-677003 ancestors = self.class.ancestors test_case = ancestors[ancestors.index(ActionController::TestCase) - 1] @controller = test_case.controller_class.new end class_eval &block end end end
Put that in your