Skip to content
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

v6.0.0 breaks if a helper spec subject is named name or if a helper module defines a #name method with arguments #2624

Closed
magni- opened this issue Oct 13, 2022 · 5 comments

Comments

@magni-
Copy link

magni- commented Oct 13, 2022

What Ruby, Rails and RSpec versions are you using?

Ruby version: 3.0.3
Rails version: 7.0.3.1
RSpec version: 6.0.0

Observed behaviour

We had a helper spec start to fail when attempting to upgrade rspec-rails to v6.0.0. While debugging to figure out why it was just the one helper spec that failed (while many others continued passing), I figured out the issue had to do with the helper in question defining a method called #name. We usually name our subjects after the method they're testing. In this case, switching to an unnamed subject caused a different error: it turned out there are two separate issues.

When using subject(:name)

NoMethodError: undefined method `view_context' for nil:NilClass

When defining a #name helper with at least one argument

ArgumentError: wrong number of arguments (given 0, expected 1)
This breaks all specs in the file, not just the specs for #name

Expected behaviour

The specs in the example app should all pass.

Can you provide an example app?

https://github.com/magni-/rspec-rails-dummy

@pirj
Copy link
Member

pirj commented Oct 13, 2022

Oh I was wrong

@JonRowe
Copy link
Member

JonRowe commented Oct 14, 2022

It turns out the module has a setup hook which is triggered which uses #name, so in #2625 I've replaced it with the method by hand, that branch should fix the issue @magni-

@magni-
Copy link
Author

magni- commented Oct 17, 2022

@JonRowe Thanks for the speedy fix! I've updated https://github.com/magni-/rspec-rails-dummy, this fixes the errors seen on 6.0.0 👍🏼

If you try running the specs yourself, you'll see there's still a couple of errors, but those were already present on 5.1.2 and seem to be due to helper including all helpers rather than just the one being described, which breaks when multiple helpers define a method with the same name. I don't know if that's worth opening another Issue for or if it's As Designed ? (I couldn't find where in the RSpec or Rails internals this behavior was coming from. I'm guessing it's here, but I couldn't see where _helpers was getting set).

@JonRowe
Copy link
Member

JonRowe commented Oct 17, 2022

The last two specs seem to be Rails behaviour due to the overlapping method names, its not something we control we just provide access to an action view testcase.

@magni-
Copy link
Author

magni- commented Oct 19, 2022

Dependabot PR for 6.0.1 came in, our build passed ☺️

@magni- magni- closed this as completed Oct 19, 2022
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

No branches or pull requests

3 participants