Skip to content

Instantly share code, notes, and snippets.

@trevorturk

trevorturk/1.md Secret

Created June 16, 2021 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevorturk/4fc8373e25f0cb0ec2afb831361cd524 to your computer and use it in GitHub Desktop.
Save trevorturk/4fc8373e25f0cb0ec2afb831361cd524 to your computer and use it in GitHub Desktop.

Starting in Ruby 3.0, many gems are now "bundled gems" which are not required by default. I believe the recommended fix for a gem like geokit which requires rexml is to use add_dependency in the gemspec as I've done here. I'm also adding a condition to limit this to Ruby 3.0+ which may not be advisable (see updates below...)

Re: https://bugs.ruby-lang.org/issues/5481 Details: https://stackoverflow.com/questions/65479863/rails-6-1-ruby-3-0-0-tests-error-as-they-cannot-load-rexml/66427936#66427936 Gemspec workaround via: https://www.tiredpixel.com/2014/01/05/curses-conditional-ruby-gem-installation-within-a-gemspec/

/cc @ioquatix who informed me of the issue.

Note that geokit users can also simply add rexml to their Gemfile to work around the issue in the meantime.

Update 1:

It appears CI has failed for Ruby 2.0. I'm investigating to see if the RUBY_VERSION check is not working as expected, or if it's not recommended. So far it appears the recommendation may be to bump the required_ruby_version which may be controversial.

Update 2:

After reading ruby/rexml#70 I'm attempting to bump the required_ruby_version and use add_dependency. I'm honestly not sure what the best strategy is here. Perhaps a third option would be to use a post install message to inform Ruby 3.0+ users to add rexml to their Gemfile and leave it at that? (I found an example like that here: rafaelsales/ulid#17.)

Update 3:

Adding a post_install_message still causes CI to fail on Ruby 2.0, and I'm not sure why. I'm giving up for now, but hope this PR can help start a discussion about how best to handle the rexml issue with Ruby 3.0. Apologies for the noisy PR description as I worked on the issue!

/cc @olleolleolle in case you have any ideas, thank you!

Update 4:

After chatting with @olleolleolle, giving another attempt to bump the required_ruby_version to at least 2.5.0 and also updating the travis.yml config to test against all currently in-support Ruby versions (found in https://www.ruby-lang.org/en/downloads/, but also including 2.5.9 which is technically already EOL but still listed here.)

Update 5:

Attempting to fix the specs after reading bblimke/webmock#683 which recommends updating webmock to at least 2.3.2. This seems to solve some issues, but others remained involving string matching. I'm not clear on what's going on here, but I stepped through the failures and updated the expected strings to match the actuals. Apologies if this is incorrect (it may well be) but to my eye it looks like primarily capitalization issues? My hope is that these updates may expected, but I'll need to defer to someone else to help investigate.

Update 6:

Tests now pass with Ruby 2, but not with Ruby 3. I believe I've reached the end of my patience for now! 😬

Update 7:

Chatting with @olleolleolle a bit more and thought I'd try localizing the rexml require to only happen if we're dealing with xml, and then rescuing the possible LoadError with a logger.error with details before re-raising.

Again, I'm not sure if this is the best fix, but I ran into issues with testing EOL Ruby versions etc and not sure what's best. Perhaps we should consider updating things to require nokogiri for xml or something along those lines?

I'm happy to work up alternate ideas here, and at a minimum hopefully this issue will point people to the workaround solution and some ideas for updating geokit in some smarter way than I have!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment