Here's an approach someone took using cram:
Is there something like VCR (http-interaction stubbing/replay) for commandline calls?
-
27-06-2022 - |
Domanda
I am developing a system that has a lot of commandline interaction. Sometimes even over SSH. Commands can take as long as 30minutes sometimes to finish.
Currently I am stubbing out most of the system
calls on the objects doing that system call. E.g:
class BackupBuilderTest < ActiveSupport::TestCase
test "it calls the backup utility over ssh" do
BackupBuilder.expects(:system).with("ssh foo@bar backup").returns(true)
BackupBuilder.perform(:id => @backup.id)
end
end
BackupBuilder
def perform
system("ssh foo@bar backup")
end
end
However, a command like ssh foo@bar backup
can fail on a lot of levels, and will output a lot of data, which I capture and act on. It also takes a long time to run; not a good thing in integration tests and unacceptable in unit-tests.
I'd like to run this, whithout having all the actual ssh
and backups running.
For HTTP there is VCR, which does nearly exactly what I'd like to do on my CLI-calls. Is there something for this? Or am I missing some pattern or common stubbing-trick that allows me to do this?
Soluzione