ruby-on-railsrubydebuggingpry-rails

Why `binding.pry` halts at the wrong place?


For some reason when I set a breakpoint using binding.pry, the program ends up halting at a totally different (and alien looking!) place. Am I doing it wrong?

Gemfile (shortended)

gem "rails", "~> 4.1"
gem "pry"
gem "pry-rails"
gem "pry-doc"
gem "pry-stack_explorer"
gem "pry-byebug"

Scenario

Break point:

class SomeController < Application controller
  before_filter :filter
  ...
  def filter
    assignment = SkillAssignment.where(day: selected_date).first

    if assignment
      @day_skill = assignment.skill
      @day_description = @day_skill.description
    end

    binding.pry
  end
end

Where I land (using show-source):

[1] pry(ActiveSupport::Callbacks::Filters::Before)> show-source

From: /home/yan-foto/workspaces/my-app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb @ line 156:
Owner: #<Class:ActiveSupport::Callbacks::Filters::Before>
Visibility: private
Number of lines: 16

def self.halting(next_callback, user_callback, halted_lambda, filter)
  lambda { |env|
    target = env.target
    value  = env.value
    halted = env.halted

    unless halted
      result = user_callback.call target, value
      env.halted = halted_lambda.call(target, result)
      if env.halted
        target.send :halted_callback_hook, filter
      end
    end
    next_callback.call env
  }
end

Solution

  • Thanks to @Manuel and @Anthony I know now that this problem is caused by a bug in pry-byebug. Unfortunately this doesn't seem to be fixed any soon as mentioned by the developer in GitHub:

    The current situation is that I hardly ever use pry-byebug, so I feel less motivated to mantain software I don't use. :(

    If you want to have the binding.pry at the end line, a simple workaround would be to write something like this:

    def myMethod
      # magic
      binding.pry
      1 + 1
    end