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
Helpers from ApplicationHelper are included when they shouldn't be #831
Comments
@alindeman or @dchelimsky can you shed light on why we do this? |
Hmm, actually, those two lines may not be the problem. I removed both of them and BTW, I'm using RSpec Rails 2.11.4 and Rails 3.2.11. |
Well AFAIK the default Rails behaviour is to include |
Not if the application controller is namespaced and I call |
I've done some more investigation. Calling |
The problem seems to be in Rails. The controller used in a view spec has nothing to do with the controller used when viewing the site. Instead the controller in the view spec is an instance of this class: I managed to monkey patch Rails to set the controller class in the view spec. Now I can use a controller looking like this: class Admin::ApplicationController < ActionView::TestCase::TestController
clear_helpers
end Now I've instead encountered what I thought was my original problem, this: https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example/view_example_group.rb#L21 The above code was added in this commit: a4200ef. I guess it was added to work correctly when using a config, like this: config.action_controller.include_all_helpers = false But the helpers should not be added if |
For the most part we won't monkey patch Rails to fix their issues, we open PR's to help them, is there anything left that is actually an issue within RSpec? |
I understand that.
Yes, this code should not be called if |
I created an issue for Rails, rails/rails#12432. I've been thinking a bit about this. The standard Rails test system works differently when it comes to views. To test the views it seems one needs to use functional tests. As far as I can see, they're basically not making any difference between tests for controller and tests for views. This might actually be an RSpec problem after all, I'm not sure. |
If your view tests are isolated from your controller, then |
I just want the correct helpers to be available to the view. I guess I probably should have created an engine, or something like that. |
I'm open to a PR that adds a |
Cool, I see what I can do. |
Ping, @jacob-carlborg is this still something you're interested in? |
@cupakromer no, most likely not. Sorry. |
Close as this is no longer requested. |
We have an Rails application with two application controllers, one standard,
ApplicationController
and one namespaced toAdmin::ApplicationController
. Both of these two inherit fromActionController::Base
, so they are completely separated.When I normally run this application
ApplictionHelper
is only included whenApplicationController
is used andAdmin::ApplictionHelper
is only included whenAdmin::ApplicationController
is used. But when I run the specs for this applicationApplictionHelper
is always included, regardless if I test a view or helper which is namespaced toadmin
or not.The issue is here:
https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example/helper_example_group.rb#L21
And here:
https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example/view_example_group.rb#L21
The text was updated successfully, but these errors were encountered: