Skip to content

Allow rspec-rails to load without Rubygems loaded #1099

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
Jun 20, 2014

Conversation

wanelo-pair
Copy link

Rspec-rails is a great gem citizen, and doesn't explicitly require Rubygems anywhere. However, while working on a Rails app that doesn't require Rubygems before loading Rails, we've noticed that rspec-rails expects Rubygems to be loaded even though it doesn't require it.

This pull request simply checks for Rubygems before calling Rubygems methods, so that rspec-rails works without Rubygems already being loaded.

@indirect
Copy link
Contributor

👍

@fables-tales
Copy link
Member

this is LGTM. @cupakromer @myronmarston got thoughts?

@myronmarston
Copy link
Member

This LGTM, although I wonder if we can take it a step further and just use require 'minitest' with no gem statement at all...why is that even needed?

@indirect
Copy link
Contributor

Minitest itself tells you to "gem 'minitest'". AFAIK, you could just require it, though.

On Tue, Jun 17, 2014 at 10:33 AM, Myron Marston [email protected]
wrote:

This LGTM, although I wonder if we can take it a step further and just use require 'minitest' with no gem statement at all...why is that even needed?

Reply to this email directly or view it on GitHub:
#1099 (comment)

@myronmarston
Copy link
Member

Minitest itself tells you to "gem 'minitest'". AFAIK, you could just require it, though.

Do we know what the risk of not doing gem "minitest" is?

@indirect
Copy link
Contributor

Minitest might not be loaded. :) Here's the implementation of gem. It finds a gemspec, sets up the load path, etc. With Rubygems loaded, require is intercepted to do the same thing. With Rubygems not loaded, the call to gem is totally unneeded.

@cupakromer
Copy link
Member

If we can I'd prefer to drop gem if we can. Now that Minitest is going to be out of core, but included as a gem I wonder if this will make a difference. Let me check what rails does.

@cupakromer
Copy link
Member

Right now I found: https://github.com/rails/rails/blob/e20dd73df42d63b206d221e2258cc6dc7b1e6068/activesupport/lib/active_support/testing/autorun.rb

Though that doesn't appear to be required in any lib path. Seems it's manually added to test_helper. The current rails master branch puts minitest in it's gemspec, so it will get setup that way and it seems they just use normal require.

We'd need to check the different rails 3.x versions too :-/

@indirect
Copy link
Contributor

I have an open pull request with rails to stop calling gem if it's not defined as well. I'm happy with just a conditional, but I'm also pretty sure that dropping them gem call will work just fine.

On Tue, Jun 17, 2014 at 12:01 PM, Aaron Kromer [email protected]
wrote:

Right now I found: https://github.com/rails/rails/blob/e20dd73df42d63b206d221e2258cc6dc7b1e6068/activesupport/lib/active_support/testing/autorun.rb
Though that doesn't appear to be required in any lib path. Seems it's manually added to test_helper. The current rails master branch puts minitest in it's gemspec, so it will get setup that way and it seems they just use normal require.

We'd need to check the different rails 3.x versions too :-/

Reply to this email directly or view it on GitHub:
#1099 (comment)

@myronmarston
Copy link
Member

Thinking about this some more...it'd be nice to drop the gem 'minitest' entirely but there's risk of breakage for users, and I don't think the benefit of dropping it is enough to warrant dropping it in a 3.x release. Maybe in 4.0?

@indirect
Copy link
Contributor

I’m perfectly happy with not dropping it, I’m just hoping to not call it if rubygems isn’t loaded. :)

On Jun 17, 2014, at 12:36 PM, Myron Marston [email protected] wrote:

Thinking about this some more...it'd be nice to drop the gem 'minitest' entirely but there's risk of breakage for users, and I don't think the benefit of dropping it is enough to warrant dropping it in a 3.x release. Maybe in 4.0?


Reply to this email directly or view it on GitHub.

@wanelo-pair
Copy link
Author

Is there anything I can change that would make this pull more acceptable? Thanks!

@myronmarston
Copy link
Member

It looks fine to me as-is. One part of the travis build failed with a transient error, so I restarted it. I'll leave it to @cupakromer to merge it.

@cupakromer
Copy link
Member

Yeah, I'm good with this. I plan on leaving this on the 3.1.x line only as a new feature. Let me know if anyone has any objections to that.

cupakromer added a commit that referenced this pull request Jun 20, 2014
Allow rspec-rails to load without Rubygems loaded
@cupakromer cupakromer merged commit eb9ac99 into rspec:master Jun 20, 2014
@myronmarston
Copy link
Member

Yeah, I'm good with this. I plan on leaving this on the 3.1.x line only as a new feature. Let me know if anyone has any objections to that.

It's your call on this, but my instinct is that this is a bug fix. Without this change, don't users get a NoMethodError "gem" if rubygems is not loaded? I generally try to include all bug fixes in the next patch release unless there's some reason not to.

@JonRowe
Copy link
Member

JonRowe commented Jun 21, 2014

I'd say this was a bug fix too.

@cupakromer
Copy link
Member

K. Done and done. (ᵔᴥᵔ)

cupakromer added a commit that referenced this pull request Jun 21, 2014
cupakromer added a commit that referenced this pull request Jun 21, 2014
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.

6 participants