-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Not every project has an ::AplicationController #922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
As a workaround you can specify your own base class: describe "my controller anonymously" do
controller(MyController) do
end
end or ask RSpec to infer the controller from the RSpec.configuration.infer_base_class_for_anonymous_controllers = true
describe MyController do
controller do
end
end |
|
Note you'll need to have correct constant name in your top level describe for it to work... |
Your suggestion don't work since there is no class ::ApplicationController and you are trying to use it.
The only solution for me is to create a class application_controller.rb or all my specs blow up. |
Check the test failures and it should be pretty obvious that whoever wrote that code never thought there could be a project where there is no ApplicationController in the root namespace. |
Given that it's a Rails convention to have one it's a fairly safe assumption |
But won't this be a problem for engines? All namespaced projects etc as well? I find it hard to believe I will be the only one. |
shrug Most projects also have a root namespace, and engines probably don't use anonymous controllers. Personally I've not see anyone use them in the "wild". |
I'm not saying we won't fix it by the way. |
PR's accepted, although I'd prefer an additional test (hint use |
Deal! Didn't know that was what it was for Sent from my iPhone
|
I think it's reasonable for rspec-rails to assume there is an ApplicationController which is generated by Your tests failed because you did something customized on Rails. I think this is totally acceptable. So it would also be acceptable to do something customized on test settings instead of changing rspec-rails. May I suggest you to add such in config.before(:each, type: :controller) do
stub_const('::ApplicationController')
end If only one or two files need such you can add them directly into the files. |
You need to at least do |
Thanks! #924 addresses this, I think :) |
In our project there is no root ApplicationController and hence when you are trying to use it for comparison my anonymous controller tests blow up like the pull request suggests.