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
Martinffx
  • 2,264
  • 3
  • 28
  • 56
  • What do you mean? You cannot type anything or what? – kyrylo Feb 02 '13 at 16:26
  • 1
    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. – Martinffx Feb 05 '13 at 12:20
  • Is there any news on this? It would be really nice to have this working. – Joshua Muheim Feb 28 '14 at 11:22
  • Don't know if it is the case, but have you guys seen [this post](https://github.com/guard/guard/wiki/Add-Readline-support-to-Ruby-on-Mac-OS-X) on Guard's Wiki GitHub? – warantesbr Mar 07 '14 at 08:24

2 Answers2

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.

Screamer
  • 1,031
  • 10
  • 13
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
Costi
  • 1,201
  • 2
  • 11
  • 18