rabbit-shocker/rabbit

Gem::Specification#loaded? is removed

Closed this issue · 6 comments

okkez commented

https://github.com/rabbit-shocker/rabbit/blob/master/lib/rabbit/config.rb#L31

I'm using Rabbit 2.1.9 with RubyGems 2.5.1.
Gem::Specification#loaded? is removed on 2012-09-16 by rubygems/rubygems#375.

I could not find alternative way for Gem::Specification#loaded?.

kou commented

Why is the code used? Your Gem::Specification doesn't have activated??

Please show backtrace on your problem.

okkez commented

I forgot to paste backtrace 🙇

$ bundle exec rabbit
bundler: failed to load command: rabbit (/home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/bin/rabbit)
NoMethodError: undefined method `loaded?' for #<Bundler::StubSpecification:0x0000000158b370>
  /home/kenji/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/remote_specification.rb:81:in `method_missing'
  /home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/gems/rabbit-2.1.9/lib/rabbit/config.rb:31:in `activated?'
  /home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/gems/rabbit-2.1.9/lib/rabbit/config.rb:34:in `block in <module:Config>'
  /home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/gems/rabbit-2.1.9/lib/rabbit/config.rb:38:in `<module:Config>'
  /home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/gems/rabbit-2.1.9/lib/rabbit/config.rb:20:in `<module:Rabbit>'
  /home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/gems/rabbit-2.1.9/lib/rabbit/config.rb:19:in `<top (required)>'
  /home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/gems/rabbit-2.1.9/lib/rabbit/rabbit.rb:17:in `require'
  /home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/gems/rabbit-2.1.9/lib/rabbit/rabbit.rb:17:in `<top (required)>'
  /home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/gems/rabbit-2.1.9/lib/rabbit/console.rb:25:in `require'
  /home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/gems/rabbit-2.1.9/lib/rabbit/console.rb:25:in `<top (required)>'
  /home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/gems/rabbit-2.1.9/lib/rabbit/command/rabbit.rb:41:in `require'
  /home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/gems/rabbit-2.1.9/lib/rabbit/command/rabbit.rb:41:in `run'
  /home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/gems/rabbit-2.1.9/lib/rabbit/command/rabbit.rb:29:in `run'
  /home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/gems/rabbit-2.1.9/bin/rabbit:22:in `<top (required)>'
  /home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/bin/rabbit:23:in `load'
  /home/kenji/Data/ruby/slides/rabbit-slide-okkez-rubykaigi-2016/vendor/bundle/ruby/2.3.0/bin/rabbit:23:in `<top (required)>'
kou commented

Thanks. Bundler::RemoteSpecification should implement respond_to_missing?. Please report it to Bundler.

okkez commented

I implemented Bundler::RemoteSpecification#respond_to_missing?, but rabbit does not work well.
Still get same backtrace.

$ git diff
diff --git a/lib/bundler/remote_specification.rb b/lib/bundler/remote_specification.rb
index 6a02897..7e4309d 100644
--- a/lib/bundler/remote_specification.rb
+++ b/lib/bundler/remote_specification.rb
@@ -81,5 +81,9 @@ module Bundler
     def method_missing(method, *args, &blk)
       _remote_specification.send(method, *args, &blk)
     end
+
+    def respond_to_missing?(method, include_private)
+      _remote_specification.send(:respond_to_missing?, method, include_private)
+    end
   end
 end

https://github.com/rabbit-shocker/rabbit/blob/master/lib/rabbit/config.rb#L27

When gem install rabbit, we get Gem::Specification instance.
When install rabbit via bundle install, we get Bundler::StubSpecification instance.

Gem::Specification#activated? is defined, but Bundler::StubSpecification#activated? is not defined.
So execute https://github.com/rabbit-shocker/rabbit/blob/master/lib/rabbit/config.rb#L31 when rabbit_gem_spec is Bundler::StubSpecification instance.
Bundler::StubSpecification#loaded? is not defined, too.

I wrote following patch and works well in my environment(bundle install environment).

diff --git a/lib/rabbit/config.rb b/lib/rabbit/config.rb
index 53e156f..a45dfc9 100644
--- a/lib/rabbit/config.rb
+++ b/lib/rabbit/config.rb
@@ -28,7 +28,7 @@ module Rabbit
       return if rabbit_gem_spec.nil?
       unless rabbit_gem_spec.respond_to?(:activated?)
         def rabbit_gem_spec.activated?
-          loaded?
+          @stub.version == version
         end
       end
       if rabbit_gem_spec.activated?
kou commented
+      _remote_specification.send(:respond_to_missing?, method, include_private)

Why did you call respond_to_missing?? It should be respond_to? because RemoteSpecification should not care whether the method is defined as method_missing or not.

okkez commented

Thank you for comment.
I don't know about respond_to_missing? at all.
Replacing respond_to_missing? with respond_to? works well.