【发布时间】:2013-12-20 02:03:07
【问题描述】:
我有一个运行 ssh 会话的 ruby 脚本 (scratch/ssh.rb):
require 'net/ssh'
require 'net/ssh/shell'
def try_process
Net::SSH.start('host', 'username', {:password=>'pwd'}) do |ssh|
end
end
我写了一个规范(spec/test_ssh.rb)如下:
require 'scratch/ssh'
describe 'SSH Tester' do
it "should work" do
try_process
end
end
我尝试按如下方式运行规范:
bundle exec rspec -I. spec/test_ssh.rb
并得到以下结果:
Failures:
1) SSH Tester should work
Failure/Error: try_process
NoMethodError:
undefined method `timeout' for #<Net::SSH::Transport::Session:0x000000036d5288>
# ./scratch/ssh.rb:6:in `try_process'
# ./spec/test_ssh.rb:5:in `block (2 levels) in <top (required)>'
有趣的是,运行 ssh.rb 本身会成功,所以我认为它与 RSpec 有关。
我尝试查找 net-ssh 源并发现 here 它确实使用了“超时”,这似乎是一个合法的 Ruby 模块。
我怀疑这可能是由于 rspec 使用不同/删减版本的 Ruby 解释器来运行测试,但我不知道如何检查它。我在规范中尝试put LOAD_PATH,但它没有显示任何可疑之处。
Ruby 版本:1.9.3 Rspec 版本:2.14.7 net-ssh 版本:2.1.4
有没有人知道我需要在哪里挖掘才能解决这个问题?
非常感谢!
【问题讨论】:
-
当您说“运行 ssh.rb 本身成功”时,您的意思是直接运行它还是运行它然后调用 try_process?
-
我在irb中试过如下:load
'scratch/ssh.rb'; try_process