Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Rspec net ssh会话抛出NoMethodError_Ruby_Rspec_Net Ssh - Fatal编程技术网

Ruby Rspec net ssh会话抛出NoMethodError

Ruby Rspec net ssh会话抛出NoMethodError,ruby,rspec,net-ssh,Ruby,Rspec,Net Ssh,我有一个运行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 T

我有一个运行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
我尝试按如下方式运行spec:

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)>'
故障:
1) SSH测试人员应该可以工作
失败/错误:尝试\u进程
命名错误:
未定义的方法“超时”#
#./scratch/ssh.rb:6:in'try_process'
#./spec/test_ssh.rb:5:in'block(2层)in'
有趣的是,运行ssh.rb本身就成功了,所以我认为它与RSpec有关

我试图查找netssh源代码,发现它确实使用了“timeout”,这似乎是一个合法的Ruby模块

我怀疑这可能是因为rspec使用不同的/剪切版本的Ruby解释器来运行测试,但我不知道如何检查它。我试图在spec中放置LOAD_2;PATH但它没有显示任何可疑的东西

Ruby版本:1.9.3 Rspec版本:2.14.7 net ssh版本:2.1.4

有没有人知道我需要在哪里挖掘来解决这个问题


非常感谢

不管怎样,我试图重现你的问题,但没有成功

具体而言,以下代码:

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 #
F
失败:
1)  
失败/错误:Net::SSH.start('123.123.123.123',{})do|SSH|
错误号::ETIMEDOUT:
操作超时-连接(2)
#/tmp/so_规范rb:5:in“try_流程”
#/tmp/so_规范rb:11:in‘块(2层)in’
以1分15秒69的成绩完成
1例,1例失败
失败的示例:
rspec./tmp/so_规范rb:10#
表示在RSpec块中,
超时
方法仍然可以访问


这个测试是用Ruby 2.0.0p247和RSpec 2.14.5完成的,当你说“自己运行ssh.rb成功”时,你的意思是仅仅运行它还是运行它然后调用try_进程?我在irb中做了如下尝试:load
'scratch/ssh.rb';试试这个进程吧。如果我在ruby-2.0.0上试用的话,它确实可以工作。这似乎是一个Ruby版本的问题。谢谢