Question

I have a ruby script (scratch/ssh.rb) that runs an ssh session:

require 'net/ssh'
require 'net/ssh/shell'

def try_process
    Net::SSH.start('host', 'username', {:password=>'pwd'}) do |ssh|
    end
end

I wrote a spec (spec/test_ssh.rb) as follows:

require 'scratch/ssh'

describe 'SSH Tester' do
  it "should work" do
    try_process
  end
end

I try to run spec as follows:

bundle exec rspec -I. spec/test_ssh.rb

And get the following result:

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)>'

Interestingly, running ssh.rb itself succeeds, so I assume it has something to do with RSpec.

I tried to look up net-ssh source and found here that it indeed uses 'timeout' which appears to be a legitimate Ruby module.

I suspected that it could be due to the fact that rspec uses a different/cut version of Ruby interpreter to run tests, but I don't know how to check it. I tried to put LOAD_PATH in spec, but it does not show anything suspicious.

Ruby version: 1.9.3 Rspec version: 2.14.7 net-ssh version: 2.1.4

Does anyone have an idea where I need to dig to figure this out?

Thanks a lot!

Was it helpful?

Solution

For what it's worth, I tried to reproduce your problem, but wasn't able to.

Specifically, the following code:

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

produced the following output:

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 #

indicating that the timeout method remained accessible within the RSpec block.

This testing was done with Ruby 2.0.0p247 and RSpec 2.14.5

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top