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!
For what it's worth, I tried to reproduce your problem, but wasn't able to.
Specifically, the following code:
produced the following output:
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