ranmocy / guard-rails

Guard-Rails is watching on your development servers as you wish!
http://ranmocy.github.com/guard-rails
MIT License
137 stars 25 forks source link

binding.pry doesn't work #24

Closed jmuheim closed 10 years ago

jmuheim commented 10 years ago

When starting rails server on the console, I can add a binding.pry wherever I want it, hit reload, and then execution is halted at this line and I can interact with pry in the given context.

With Guard-Rails, this doesn't seem to work. The binding.pry is recognised, but simply omitted, which means that execution is continued without giving me the chance to interact with pry.

The output (which proves that binding.pry is recognised, see => 5: - binding.pry):


Frame number: 0/106

From: /Users/josh/Documents/Work/MuheimWebdesign/base/app/views/dashboards/show.html.slim @ line 5 ActionView::CompiledTemplates#_app_views_dashboards_show_html_slim__130432664906313828_70093845884840:

    1: h1
    2:   i.glyphicon.glyphicon-home
    3:   |Dashboards#show
    4: 
 => 5: - binding.pry

[1] base(#<#<Class:0x007f7ffd913c80>>) »  
  Rendered dashboards/show.html.slim within layouts/application (116.0ms)
  Rendered app/cells/mini_hub/show.html.slim (3.7ms)
Completed 200 OK in 255ms (Views: 230.1ms | ActiveRecord: 0.0ms)
  Rendered /Users/josh/.rvm/gems/ruby-2.0.0-p353@base/gems/xray-rails-0.1.12/app/views/_xray_bar.html.erb (8.8ms)
12:21:29 - INFO - Browser disconnected.
12:21:30 - INFO - Browser connected.
12:21:45 - INFO - Browser connected.

This question on stackoverflow asks the same, and is over a year old already: http://stackoverflow.com/questions/14153585/guard-rails-not-providing-repl-for-binding-pry

It would be really useful to have the rails output and guard input in the same window, but without pry, I'm not able to do my work.

Thanks a lot for help.

ranmocy commented 10 years ago

I can try to find how to do it. But my first feeling is that it's not easy to do. Because currently Guard-Rails start the rails process in a sub-process shell for capability. And I can't join the process since that will block the whole guard process with other guard plugins.

If I do want to support binding.pry, I think I have to rewrite the whole runner to start the rails in ruby rather than in shell. Which means it depends on how rails started and may potentially break some other gems of rails.

I think I have to study it and rethink again.

jmuheim commented 10 years ago

Thanks for at least thinking about it. :+1:

jmuheim commented 10 years ago

For others facing this issue: I'm using the rerun gem now to achieve what I want. More infos here: http://stackoverflow.com/questions/22465596/tell-webrick-to-load-everything-restart-on-next-request-something-like-restar/22500887#22500887

ranmocy commented 10 years ago

I peek into the rerun gem, it use thread and join which can't be use in guard-rails case. That will block the whole guard.

https://github.com/alexch/rerun/blob/master/lib/rerun/runner.rb#L7

def self.keep_running(cmd, options)
  runner = new(cmd, options)
  runner.start
  runner.join
  # apparently runner doesn't keep running anymore (as of Listen 2) so we have to sleep forever :-(
  sleep 10000 while true  # :-(
end

I think this is impossible with guard system.

Reopen this if you have further idea.

gerrywastaken commented 10 years ago

@ranmocy Can guard-rails at least output some sort of warning when it finds pry? At the moment there is no indication as to what is going wrong, the call is just skipped. I just spent a few hours trying to track down the issue and I imagine it will be the same for others.

ranmocy commented 10 years ago

@gerrywastaken guard can only notice pry when user run in bundle exec guard, also user commonly can directly require pry when they want to use it (I did at least). So, I'm lazy and just update the README. :)

westonganger commented 9 years ago

try using gem pry-remote

atd commented 5 years ago

For those who might be interested, I implemented a solution using pry-remote

https://github.com/atd/guard-rails

I don't care about blocking the whole guard process because I want to focus on debugging the code and I can live with handling file modifications after I exit pry-remote

suranyami commented 5 years ago

This issue doesn't seem to be a problem any more.

binding.pry works as expected using rails 5.x, ruby 2.4.

Should the documentation in the README.md?

timolehto commented 4 years ago

I'm having this same issue as I'm upgrading from Rails 5 -> 6 🤔