Ruby如何测试SSH连接是否成功?
- 内容介绍
- 文章标签
- 相关推荐
本文共计267个文字,预计阅读时间需要2分钟。
我的项目的一个重要部分是使用SSH登录远程服务器并执行一些操作:`Net:SSH.start(@host, @username, :password=@password) do |ssh| ssh.exec!('rename_files_on_remote_server') end` 如何测试呢?我想测试我能否“
我的项目的一个重要部分是使用ssh登录到远程服务器并对其执行某些操作:Net::SSH.start(@host, @username, :password => @password) do |ssh| ssh.exec!(rename_files_on_remote_server) end
怎么测试呢?
我想我可以使用本地ssh服务器并检查其上的文件名(也许它可能在我的test / spec目录中).
或许有人可以指出我更好的解决方案?
如果你确实实现了服务器,那么你需要对它进行测试,但就SSH的内容而言,我会做一些这样的嘲弄(RSpec 2语法):
describe "SSH Access" do let (:ssh_connection) { mock("SSH Connection") } before (:each) do Net::SSH.stub(:start) { ssh_connection } end it "should send rename commands to the connection" do ssh_connection.should_receive(:exec!).ordered.with("expected command") ssh_connection.should_receive(:exec!).ordered.with("next expected command") SSHAccessClass.rename_files! end end
本文共计267个文字,预计阅读时间需要2分钟。
我的项目的一个重要部分是使用SSH登录远程服务器并执行一些操作:`Net:SSH.start(@host, @username, :password=@password) do |ssh| ssh.exec!('rename_files_on_remote_server') end` 如何测试呢?我想测试我能否“
我的项目的一个重要部分是使用ssh登录到远程服务器并对其执行某些操作:Net::SSH.start(@host, @username, :password => @password) do |ssh| ssh.exec!(rename_files_on_remote_server) end
怎么测试呢?
我想我可以使用本地ssh服务器并检查其上的文件名(也许它可能在我的test / spec目录中).
或许有人可以指出我更好的解决方案?
如果你确实实现了服务器,那么你需要对它进行测试,但就SSH的内容而言,我会做一些这样的嘲弄(RSpec 2语法):
describe "SSH Access" do let (:ssh_connection) { mock("SSH Connection") } before (:each) do Net::SSH.stub(:start) { ssh_connection } end it "should send rename commands to the connection" do ssh_connection.should_receive(:exec!).ordered.with("expected command") ssh_connection.should_receive(:exec!).ordered.with("next expected command") SSHAccessClass.rename_files! end end

