我认为这足以测试你是否正在向ssh服务器发送正确的命令.您的应用程序可能不会实现服务器 - 因此您必须相信服务器正确地工作和测试.
如果你确实实现了服务器,那么你需要对它进行测试,但就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
Run Code Online (Sandbox Code Playgroud)