0

我用美沙酮开始了一个空白项目,美沙酮是一个用于构建命令行应用程序的很棒的框架。唯一的问题是我无法从所在的App类中进行调试bin/my_app

该类App是您运行美沙酮时创建的文件。这是我尝试使用 pry 的方式

#!/usr/bin/env ruby

require 'optparse'
require 'methadone'
require 'my_app'
require 'pry'

class App
  include Methadone::Main
  include Methadone::CLILogging

  main do
     binding.pry    #  <= pry here
  end

  ...

当我运行时,rake features我可以告诉正在运行的进程正在尝试用 pry 做一些事情,因为它会暂停几秒钟。我收到以下错误,然后 rake/cucumber 中止。

process still alive after 3 seconds (ChildProcess::TimeoutError)

我可以从黄瓜步骤、rspec 或任何其他地方很好地使用 pry,只是不能从这个App类的任何地方使用。

一件非常有趣的事情是,如果我从控制台运行我的命令行应用程序,它将在 pry 所在的位置停止。使用黄瓜时,它只是不会被撬开。

我如何在运行时让应用程序与 pry 一起工作rake features

更新

抱歉,我应该澄清一下美沙酮是随 aruba 一起提供的。所以我的黄瓜场景看起来像这样

When I successfully run `my_app arg1`

但是,如果我运行它,它将进入调试/撬动

bundle exec bin/my_app
4

2 回答 2

1

Aruba 在一个完全独立的进程中运行应用程序,所以我猜发生的情况是,当 aruba 运行您的应用程序时,pry 会在提示符下启动并等待输入。由于它没有得到任何信息,因此 aruba 会在三秒后超时(默认情况下它将等待应用程序完成)。这就是为什么您会看到“进程仍然存在”问题。

I'm not 100% sure how you could get the standard input of your shell that's running rake features to connect to your app's standard input so you could issue pry commands, but I don't think aruba was designed to allow this.

You have a couple of options:

  • Tag your scenario with @announce, and use When I run interactively... followed by several When I type - these commands should go to the interactive pry console that's waiting. Kind of kludgy, but it might work
  • Execute a unit test of your App class. You'll need to replace the call to go! with something like go! if $0 == __FILE__ so that you can require your executable in a test and manipulate App directly.

I have not tried either of these, but the second option feels a bit better and could also be improved with support from the library, if you can figure out a good way to do this.

于 2012-09-10T02:27:07.603 回答
1

Use pry-remote to connect to a pry session in the Aruba-managed subprocess.

(Disclosure: I paired with @Dty to come to this solution)

于 2012-10-05T02:37:10.613 回答