I updated my app to Sinatra 2.0.4 which has ActiveSupport in its Gemfile. In my application, I have:
Bundler.require(:default)
But my application now breaks when trying to load Sinatra:
~/.rvm/gems/ruby-2.4.1/gems/sinatra-2.0.4/lib/sinatra/indifferent_hash.rb:16:in `require': cannot load such file -- active_support/core_ext/hash/conversions (LoadError)
from ~/.rvm/gems/ruby-2.4.1/gems/sinatra-2.0.4/lib/sinatra/indifferent_hash.rb:16:in `<top (required)>'
from ~/.rvm/gems/ruby-2.4.1/gems/sinatra-2.0.4/lib/sinatra/base.rb:18:in `require'
from ~/.rvm/gems/ruby-2.4.1/gems/sinatra-2.0.4/lib/sinatra/base.rb:18:in `<top (required)>'
from ~/.rvm/gems/ruby-2.4.1/gems/sinatra-2.0.4/lib/sinatra/main.rb:1:in `require'
from ~/.rvm/gems/ruby-2.4.1/gems/sinatra-2.0.4/lib/sinatra/main.rb:1:in `<top (required)>'
from ~/.rvm/gems/ruby-2.4.1/gems/sinatra-2.0.4/lib/sinatra.rb:1:in `require'
from ~/.rvm/gems/ruby-2.4.1/gems/sinatra-2.0.4/lib/sinatra.rb:1:in `<top (required)>'
from ~/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/runtime.rb:81:in `require'
from ~/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
from ~/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `each'
from ~/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `block in require'
from ~/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `each'
from ~/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `require'
from ~/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler.rb:114:in `require'
from /my_application/app.rb:3:in `<top (required)>' # This is the line with Bundler.require(:default)
My application doesn't use the active support gem and this is why it's not found. I'm not sure why adding this dependency breaks my application, but it does
Hi @daveroberts, I'm sorry that you're experiencing this issue. It's fixed in master and will hopefully be released with Sinatra 2.0.5. If you want to know more, read on.
I updated my app to Sinatra 2.0.4 which has ActiveSupport in its Gemfile.
Sinatra has ActiveSupport in its Gemfile as a development dependency (effectively), which means it doesn't get added to your bundle. This is the cause of your issue: ActiveSupport isn't in your bundle, so Sinatra::IndifferentHash can't load it. The bug is actually in the logic for Sinatra::IndifferentHash that is trying to work around a different issue. Note that this only happens in test; development and production are not (or at least, should not be) affected.
Here are your workaround options (any one will do):
gem 'activesupport', '~> 5.0', require: false (so that only the relevant modules get loaded, only in test) to your GemfileAgain, I apologize for the inconvenience, and the fix should be released soon.
@mwpastore how come upgrading to Ruby 2.5.0 resolves the issue? (just curious)
@dentarg The errant logic in Sinatra::IndifferentHash only fires if Hash#slice is not defined. Ruby 2.5 has Hash#slice built-in!
Thank you @mwpastore
The workaround I chose was to downgrade to Sinatra 2.0.3. Is there any reason I should avoid this as a workaround?
@daveroberts If you're using Sinatra without ActiveSupport, 2.0.3 should be fine, although there are a few other bug fixes in 2.0.4 that you're missing out on. I think it's probably fine.