28

我正在使用护栏来运行我的rails服务器,我的问题是当我添加绑定时我无法访问REPL。我刚刚得到

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>)> 

没有 REPL,我如何使用 pry 和护栏?

我的 Gemfile 文件看起来像这样

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

我的保护文件:

guard 'rails', :debugger => true do
  watch('Gemfile.lock')
  watch(%r{^(config|lib)/.*})
end
4

2 回答 2

5

我已经用 Guard 和 Spork 设置了我的 rails 环境,我发现 binding-pry 对 guard 的行为很奇怪。如果我将 binding.pry 插入代码中,然后 guard 重新启动我的测试,则没有交互式调试。但是,如果我退出并再次开始警戒,它就会正常工作并正确地进入交互模式。

但是...如果我随后删除 binding.pry 行,guard 将按预期重新运行测试,但会在绑定行曾经所在的位置中断,即使它不再存在。

似乎每次插入或删除撬绑定时都必须重新启动防护。

令人恼火,但总比无法在测试中进行撬动要好。

于 2013-07-18T09:44:25.017 回答
3

我正在尝试类似的事情,也无法让它工作。这个问题似乎从 stdin 读取不会阻塞,所以 Pry 不会阻塞。从 STDIN 读取的任何内容都会立即返回。

rspec -X console.rb

文件如下:

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
于 2013-03-26T16:15:05.910 回答