-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Rescue TypeError if a top-level class named Behavior exists #1656
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
If your application defines a top-level class named Behavior, loading rspec/rails/example/request_example_group.rb with Rails 3.2.22.1 results in a compiler warning: `warning: toplevel constant Behavior referenced by ActionDispatch::IntegrationTest::Behavior` This warning is the result of the situation descibed in rails/rails#6931, i.e. Rails auto-load magic concludes that the constant named Behavior is already defined, and tries to use it instead of attempting to auto-load a properly namespaced one. The result is a TypeError, which can safely be swallowed.
Er no, this can't be safely swallowed, as the wrong module is now included in |
Please open an issue with the rails team about this. |
If I address it this way, will you accept the PR? |
No it can't because the module behaviour is now not included, Ruby cannot have both a class and a module with the same name, if an error occurs expected functionality has not occured.
They can they can load there module properly by fully qualifying it or swallowing the exception themselves if they think it's safe, this is not a general solution but it will fix this particular case.
This won't fix it.
No, this should be addressed upstream, we are referencing a full qualified constant and it is producing a error based on its internals, those internals should be fixed. |
What module behavior? In Rails 3 and 4, there is no such module. In Rail 5,
Shouldn't this be a good enough reason to fix it here even upstream changes would make it behave differently?
I must really be missing something here. If rspec-rails can safely swallow a NameError, that means that in Rails 3 and 4, it doesn't need this module. So why won't this fix it? I made a mistake by linking to the Rails issue. I thought that would help by making it unnecessary to repeat what was already stated there, but it seems that instead it just gave the false impression that this is not a flaw in rspec-rails. |
Using exceptions for flow control is generally a bad idea, so I'd definitely be in favor of doing a version check instead of attempting inclusion with a |
@betesh if you want to convert the check to an if go ahead, but it won't fix any errors caused by |
But it'll make rspec-rails avoid trying to load |
Done. See #1660 Would it be possible to release this as v3.5.1, compatible with rspec v3.5.0? |
Don't swallow exceptions for flow control. fixes #1656
Don't swallow exceptions for flow control. fixes #1656
If your application defines a top-level class named Behavior, loading
rspec/rails/example/request_example_group.rb with Rails 3.2.22.1
results in a compiler warning:
warning: toplevel constant Behavior referenced by ActionDispatch::IntegrationTest::Behavior
This warning is the result of the situation descibed in rails/rails#6931,
i.e. Rails auto-load magic concludes that the constant named Behavior is already
defined, and tries to use it instead of attempting to auto-load a properly namespaced one.
The result is a TypeError, which can safely be swallowed.