possible to debug/pry from methadone's App class?
-
01-07-2021 - |
質問
I started a blank project with methadone, an awesome framework for building command line apps. The only problem is that I am unable to debug from within the App
class that's in bin/my_app
The App
class is a file created when you run methadone. Here's how I'm trying to use 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
...
When I run rake features
I can tell the running process is trying to do something with pry since it pauses for a few seconds. I get the following error and then rake/cucumber is aborted.
process still alive after 3 seconds (ChildProcess::TimeoutError)
I can use pry just fine from the cucumber steps, rspec, or any other place, just not from anywhere in this App
class.
One very interesting thing is that if I run my command line app from the console it WILL stop where pry is. It just wont pop into pry when using cucumber.
How can I get the app to work with pry when I'm running rake features
?
Update
Sorry, I should clarify that methadone comes with aruba. So my cucumber scenario would look like this
When I successfully run `my_app arg1`
However, it WILL go into debug/pry if I run it with
bundle exec bin/my_app
解決
Use pry-remote to connect to a pry session in the Aruba-managed subprocess.
(Disclosure: I paired with @Dty to come to this solution)
他のヒント
Aruba runs the app in a totally separate process, so I would guess what's happening is that when aruba runs your app, pry starts up at a prompt and waits for input. Since it doesn't get any, aruba times out after three seconds (the default it will wait for an app to complete). This is why you see the "process still alive" issue.
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 severalWhen 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 togo!
with something likego! if $0 == __FILE__
so that you canrequire
your executable in a test and manipulateApp
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.