Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guard-rails not providing REPL for binding.pry

Tags:

pry

guard

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
like image 201
Martinffx Avatar asked Jan 04 '13 08:01

Martinffx


People also ask

Why is binding pry not working?

To fix this just move the binding. pry command one line to the top and try to run your file again. If it still doesn't catch it, move the binding. pry command one more line to the top and keep doing this until your file catches the binding.

How do you get to the next step in binding pry?

If you're in regular old Pry you can use exit to go to the next binding. pry or disable-pry to exit Pry entirely.

Where should binding pry be placed?

Now to use Pry, you'll first have to install it in your environment. You can either put gem 'pry' in your Gemfile and bundle install, or manually type gem install pry into your terminal. After we've installed it, then we'll have to require it in our environment with the line require 'pry' , write binding.


2 Answers

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.

like image 75
Screamer Avatar answered Oct 24 '22 08:10

Screamer


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
like image 37
Costi Avatar answered Oct 24 '22 08:10

Costi