Skip to content

Check need_auto_run= method is defined also #1350

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 2 commits into from
Apr 16, 2015
Merged

Check need_auto_run= method is defined also #1350

merged 2 commits into from
Apr 16, 2015

Conversation

orien
Copy link
Contributor

@orien orien commented Apr 9, 2015

To prevent errors such as:

undefined method `need_auto_run=' for Test::Unit::AutoRunner:Class (NoMethodError)
/Users/orien/src/marketplace/.bundle/ruby/2.1.0/gems/rspec-rails-3.2.1/lib/rspec/rails/adapters.rb:65:in `<module:Rails>'
/Users/orien/src/marketplace/.bundle/ruby/2.1.0/gems/rspec-rails-3.2.1/lib/rspec/rails/adapters.rb:7:in `<module:RSpec>'
/Users/orien/src/marketplace/.bundle/ruby/2.1.0/gems/rspec-rails-3.2.1/lib/rspec/rails/adapters.rb:6:in `<top (required)>'

@@ -37,7 +37,7 @@ module Rails
# date). If so, we turn the auto runner off.
require 'test/unit'
require 'test/unit/assertions'
Test::Unit::AutoRunner.need_auto_run = false if defined?(Test::Unit::AutoRunner)
Test::Unit::AutoRunner.need_auto_run = false if defined?(Test::Unit::AutoRunner.need_auto_run = ())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh... TIL... I would have expected this to blow up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defined? is quite magical!

@JonRowe
Copy link
Member

JonRowe commented Apr 9, 2015

So why wouldn't this exist if Test::Unit::AutoRunner exists, if the method has been renamed across versions we should attempt to pick its replacement (if one exists) instead?

@orien
Copy link
Contributor Author

orien commented Apr 9, 2015

This version from the Ruby codebase doesn't have that method. It has no alternative that I can see. Compare to the test-unit gem version.

@cupakromer
Copy link
Member

So do we just need this check on line 65? As the first one should be guaranteed to use the gem?

@orien
Copy link
Contributor Author

orien commented Apr 9, 2015

@cupakromer Actually, that's the line I experienced the error.
FYI: in an app running Ruby v2.1.5 and Rails v3.2.21.

[Edit]
Sorry. I misread that comment. I agree it should be using the gem on line 40. In which case, it probably doesn't need the existing check of if defined?(Test::Unit::AutoRunner) either.

Would you like me to remove the if altogether, or just remove my change on line 40?

@cupakromer
Copy link
Member

@orien Good question. I think it was being defensive for changes in the future. In which case, your check is actually better. It seems the method was introduced sometime between the test-unit 2.4.0 and 2.4.9 gems. 👍

@cupakromer
Copy link
Member

we should attempt to pick its replacement (if one exists) instead?

@JonRowe I didn't see a clean replacement for the Ruby version. The gem version seems like it has an alternative in: Test::Unit.run=. We would need to set it to true. However, several of the gems with the newer version also have this method, but have simply deprecated it. So we would need to check for it after the newer method.

@cupakromer
Copy link
Member

@orien if you want to add the 2nd fallback for run= I think this will be good. Given we now have an additional check I think we should move the logic into a helper. Something like disable_testunit_autorun!. We can then call it from both sections of the code and let it handle all the checks.

@orien
Copy link
Contributor Author

orien commented Apr 12, 2015

@cupakromer I used a non bang version of that method name. As per http://dablog.rubypal.com/2007/8/15/bang-methods-or-danger-will-rubyist

@JonRowe
Copy link
Member

JonRowe commented Apr 12, 2015

This looks good to me :)

@cupakromer
Copy link
Member

Thanks for this @orien 💙

cupakromer added a commit that referenced this pull request Apr 16, 2015
Check `need_auto_run=` method is defined also
@cupakromer cupakromer merged commit 32f0618 into rspec:master Apr 16, 2015
cupakromer added a commit that referenced this pull request Apr 16, 2015
@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.

3 participants