Reputation: 2476
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
Upvotes: 28
Views: 1253
Reputation: 1171
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.
Upvotes: 5
Reputation: 1231
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
Upvotes: 3