25 Mar '13, 9am

SSH 叩く部分を net::ssh 使うようにして、 あたりの真似をするといいのかな。

Hi, So I'm stuck again with creating a mock for Net::SSH, I've managed to mock the call to Net::SSH.start and yield the Net::SSH mock but I am totally stuck with mocking the session.shell.sync call and will also need to mock the shell.send_command call also. Any help much appreciated. When I run the following spec I get the error: Mock 'Net::SSH' received unexpected message :shell with (no args) I've tried things like @shell = mock(Net::SSH::Service::Shell) but this also gives an error complaining that Service doe snot exist. # test code @connection = Ssh::Remote.new @ssh = mock(Net::SSH) Net::SSH.should_receive(:start).and_yield(@ssh) Net::SSH.should_receive(:shell).and_return('something') # library code require 'net/ssh' module Ssh class Remote def remote_command(server, user, commands=[]) Net::SSH.start(server, user) do |session| shell = session.shell.sync commands.each...

Full article: http://www.ruby-forum.com/topic/150299

Tweets