Guard-rails not providing REPL for binding.pry
Asked Answered
B

2

28

I'm using guard-rails to run my rails server, my problem is I can't access the REPL when I add binding.pry I just get

From: /home/martinr/code/app/controllers/tools_controller.rb @ line 2 ToolsController#index:

    2: def index
 => 3:   binding.pry
    4:   @end_date = Date.today.to_s
    5:   @start_date = Date.today.months_ago(3).to_s
    7: end

[1] pry(#<ToolsController>)> 

No REPL, how do I use pry with guard rails?

My Gemfile file looks like this

group :development, :test do
  gem 'pry-rails' # for better console debugging
  gem 'pry-debugger'
  gem 'rb-inotify'
  gem 'sqlite3'
end

My Guardfile:

guard 'rails', :debugger => true do
  watch('Gemfile.lock')
  watch(%r{^(config|lib)/.*})
end
Bluet answered 4/1, 2013 at 8:25 Comment(4)
What do you mean? You cannot type anything or what?Man
I mean that it seems to load the REPL and just continue with the programs execution. It doesn't give you a chance to interact with the REPL.Bluet
Is there any news on this? It would be really nice to have this working.Askja
Don't know if it is the case, but have you guys seen this post on Guard's Wiki GitHub?Bilbrey
G
5

I've set up my rails environment with Guard and Spork and I find that binding-pry acts strangely with guard. If I insert binding.pry into the code and then guard restarts my tests, there's no interactive debugging. But if I exit and start guard up again, it's working and breaks into interactive mode correctly.

However... if I then remove the binding.pry line, guard will rerun the tests as it is supposed to, but will break at where the binding line used to be, even though it isn't there anymore.

Seems you have to restart guard every time you insert or remove the pry binding.

Irritating but still better than not having access to pry in your tests.

Gallicize answered 18/7, 2013 at 9:44 Comment(0)
W
3

I'm trying a similar thing, and also can't get it to work. The issue seems that reading from stdin does not block, so Pry does not block. Any read from STDIN returns right away.

rspec -X console.rb

File follows:

require 'spec_helper'

describe 'console' do
  it 'opens!' do
    Pry.config.input = STDIN
    Pry.config.output = STDOUT
    puts STDIN.closed?  # returns false
    binding.pry # returns right away, does not block
    gets # returns right way, does not block
  end
end
Watertight answered 26/3, 2013 at 16:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.