FormulaMonks / FormulaMonks/contest
"@controller is nil" error in ActionController::TestCase
- Dominant language
- Ruby
- Stars
- 142
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Description
When using context() inside an ActionController::TestCase, I get the following error:
```
RuntimeError: @controller is nil: make sure you set it in your test's setup method.
```
Here is an example of what my test file looks like:
```
class ExamplesControllerTest < ActionController::TestCase
context "index action" do
should "return a list of examples" do
get :index, :format => :json
assert_response :success
end
end
end
```
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 `@controller` inside of the context() body.
Thanks for your consideration.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.