我有一个ruby脚本(scratch/ssh.rb),它运行ssh会话:
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源代码,发现这里确实使用了“timeout”,这似乎是一个合法的Ruby模块。
我怀疑这可能是因为rspec使用了不同版本的Ruby解释器来运行测试,但我不知道如何检查它。我试图在规范中使用put LOAD_PATH,但它没有显示出任何可疑之处。
Ruby版本: 1.9.3 Rspec版本: 2.14.7 net-ssh版本: 2.1.4
有谁知道我需要挖什么地方才能弄清楚吗?
非常感谢!
发布于 2013-12-19 18:03:07
不管它的价值是什么,我试图重现你的问题,但没能做到。
具体而言,以下代码:
require 'net/ssh'
require 'net/ssh/shell'
def try_process
Net::SSH.start('123.123.123.123', {}) do |ssh|
end
end
describe "" do
it "" do
try_process
end
end产出如下:
F
Failures:
1)
Failure/Error: Net::SSH.start('123.123.123.123', {}) do |ssh|
Errno::ETIMEDOUT:
Operation timed out - connect(2)
# ./tmp/so_spec.rb:5:in `try_process'
# ./tmp/so_spec.rb:11:in `block (2 levels) in <top (required)>'
Finished in 1 minute 15.69 seconds
1 example, 1 failure
Failed examples:
rspec ./tmp/so_spec.rb:10 #指示timeout方法仍可在RSpec块中访问。
这个测试是在Ruby2.0.0p247和RSpec 2.14.5中完成的。
https://stackoverflow.com/questions/20647574
复制相似问题