Skip to content

If a view example's description contains no path elements, then do not attempt to load a helper based on the example description. #1289

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

Merged
merged 1 commit into from
Mar 18, 2015

Conversation

tinynumbers
Copy link
Contributor

This odd edge case was encountered in a Rails project where a "presenter" type class was being spec'd as a ViewExampleGroup (via the type: :view). Since the example group for this class has a description with no path element, the ViewExampleGroup attempt to auto-load related helpers was trying to find (and load) a helper named Helper.

The actual issue was discovered when someone introduced (elsewhere within the specs) a class named Helper. Prior to this, the presenter example group had not caused problems since there was no Helper module or class to load, but once this new class was introduced, we started seeing an exception:

.../actionpack-3.2.21/lib/abstract_controller/helpers.rb:153:in `include': wrong argument type Class (expected Module) (TypeError)
  from .../actionpack-3.2.21/lib/abstract_controller/helpers.rb:153:in `block in add_template_helper'
  from .../actionpack-3.2.21/lib/abstract_controller/helpers.rb:153:in `module_eval'
  from .../actionpack-3.2.21/lib/abstract_controller/helpers.rb:153:in `add_template_helper'
  from .../actionpack-3.2.21/lib/abstract_controller/helpers.rb:96:in `block in helper'
  from .../actionpack-3.2.21/lib/abstract_controller/helpers.rb:95:in `each'
  from .../actionpack-3.2.21/lib/abstract_controller/helpers.rb:95:in `helper'
  from .../rspec-rails-2.14.2/lib/rspec/rails/example/view_example_group.rb:150:in `block in <module:ViewExampleGroup>'

Previously-failing example and fix provided here.

…t attempt to load a helper based on the example description.
@cupakromer
Copy link
Member

Are you rendering a view in these specs?

While I understand the root issue, I'm not sure the view spec is intended for this use case. It sounds like you are just testing a "plain old Ruby object" which happens to use parts of Rails.

@tinynumbers
Copy link
Contributor Author

@cupakromer You're right, this is a bit outside the intended use of view specs, but the PORO-ish class that is being tested actually is directly responsible for rendering (via e.g. content_tag, concat, etc), so this was setup as a view spec in order to have access to the view, params, etc that are provided by to views (and view specs).

Not at all disagreeing that the design of the test that surfaced this issue (and the object being tested) needs some reconsideration, but at the same time, what I'm pointing out here is still a (potential) bug. For example, what if you want to test a view template that sits at the root of your app/views folder?

@tinynumbers
Copy link
Contributor Author

I've created a minimal test application illustrating the requirements for reproducing this bug:

https://github.com/tinynumbers/rspec_pr_1289

The repo's Readme provides more details.

@tinynumbers
Copy link
Contributor Author

Any chance of getting this merged?

@cupakromer
Copy link
Member

This is good. Thanks for the contribution @tinynumbers ❤️

Very sorry for taking so incredibly long to merge.

cupakromer added a commit that referenced this pull request Mar 18, 2015
If a view example's description contains no path elements, then do not attempt to load a helper based on the example description.
@cupakromer cupakromer merged commit 03afd47 into rspec:master Mar 18, 2015
@tinynumbers
Copy link
Contributor Author

Thanks @cupakromer!

@tinynumbers tinynumbers deleted the view-example-helper-class-bug branch March 18, 2015 02:20
@cupakromer cupakromer mentioned this pull request May 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants