我有一个运行 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 源代码,发现这里确实使用了“超时”,这似乎是一个合法的 Ruby 模块。
我怀疑这可能是由于 rspec 使用不同/剪切版本的 Ruby 解释器来运行测试,但我不知道如何检查它。我试图put LOAD_PATH
在规范中,但它没有显示任何可疑之处。
Ruby 版本:1.9.3 Rspec 版本:2.14.7 net-ssh 版本:2.1.4
有谁知道我需要在哪里挖掘才能解决这个问题?
非常感谢!