Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Pry doesn't show code when prepended modules are used #1471
Hello, Lotus users can't make their fav debug tool to work with their apps (see hanami/hanami#205). I've isolated the problem.
# foo.rb require 'minitest/autorun' require 'pry' module CoolFeature def self.included(base) base.class_eval do prepend InstanceMethods end end module InstanceMethods def bar puts "before" super puts "after" end end end class Foo include CoolFeature def bar puts "inside" binding.pry end end describe Foo do it "uses #bar" do Foo.new.bar end end
Then, if you run the test:
It stops where the breakpoint is, but it doesn't show the code:
When I press
If I run the tests via Rake, it changes a little bit:
# Rakefile require 'rake' require 'rake/testtask' Rake::TestTask.new do |t| t.pattern = '**/*.rb' # t.libs << 'spec' end task default: :test task spec: :test
bundle exec rake
It behaves exactly the same, BUT when I type any button on the keyboard, it prints a stack trace:
changed the title from
Pry doesn't show code for when prepended modules are used
Pry doesn't show code when prepended modules are used
Sep 15, 2015
@jodosha thanks for the thorough investigation, this is very interesting! Pry hasn't quite caught up with the times yet in terms of some of the new ruby 2 features, including prepended modules and refinements (though we do have some support for refinements iirc).
I'll try to take a look at this this weekend. I know we do have some reasonable assumptions about the ancestor chain such as the 0th ancestor of a class being 'self', but this assumption is now broken by prepending functionality, fun. :)
@jodosha While I haven't found a fix yet, I've found what looks to be the root cause.
If you look at the source here: https://github.com/pry/pry/blob/master/lib/pry/method.rb#L382; you'll see that there's a method named
Hopefully that points someone into the right direction.
@talitore Unfortunately that can't be the reason cos the
@jodosha Sorry i didn't suggest this earlier, but i just tried your code on pry master and it works without problems. So whatever the problem is, it appears it's now fixed on master! Please double check to confirm! :)
seems fixed for me too.
referenced this issue
Oct 13, 2015
added a commit
Feb 22, 2016
I still have the issue in my Hanami application. However it seems that a small example app works just fine:
Anyone still having the problem in some cases that can reproduce the issue in a small example?
require "pry" module PrependThis def foo super + 1 end end class Foo prepend PrependThis def foo binding.pry 2 end end puts Foo.new.foo
Ok, I successfully reproduced this on
require "pry" module PrependThis def foo super + 1 end end module AlsoPrependThis def foo super + 2 end end class Foo prepend PrependThis prepend AlsoPrependThis def foo binding.pry 4 end end puts Foo.new.foo
@r-obert that would be awesome, I think it's due to a deep assumption in pry that the zeroeth ancestor should always be the class itself,which prepending breaks. Hopefully it's encapsulated in one place in the code and not spread around, however if it is spread around this could be a nice opportunity to refactor.