Using previous gems with latest ruby

Hi,

Is it possible to use previous gems to be used with Latest Ruby 1.9.2

Actually earlier i use Ruby 1.8.7 and netssh 1.1.2 and needle 1.3.0

I upgrade to Ruby 1.9.2.

However with Ruby 1.9.2,netssh and needle gems are intergrated, plz
correct me if im wrong, but for sure syntax are changed for netssh
commands.

I have code which i use to send commands to remote linux machine, which
is used to work preciously with Ruby 1.8.7 and netssh 1.1.2.

Code is like :

def issueCommandInKazBox(okMachine="", command="", matchLog="",
user=“admin”, passwd=“kazeon”)
puts " issueCommandInKazMachine=#{okMachine}"
puts " issueCommandInKazcommand=#{command}"
puts " issueCommandInKazstatus=#{matchLog}"
puts " issueCommandInKazuser=#{user}"
puts " issueCommandInKazpasswd=#{passwd}"

tempString = “”
Net::SSH.start(okMachine, user, :password => passwd, :paranoid => false
) do |session|
#Net::SSH.start(okMachine, user, passwd) do |session|

session.open_channel do |channel|

channel.on_success do
  puts "shell was started successfully!"

  puts "Adding command - #{command}..."

  channel.send_data "#{command}\n"

  channel.send_data "exit\n" # tell the shell to exit
end
channel.on_failure do
  puts "shell could not be started!"
end

channel.on_data do |ch,data|
  puts "recieved the following from shell"
  puts "#{data}"
  tempString = tempString + "\n" + data
end

channel.on_close do
  puts "shell terminated"
end

channel.send_request "shell", nil, true

end
session.loop
end

$_ = tempString
$outputofissueCommandInKazBox = tempString
if /#{matchLog}/
puts “PASSED! issueCommandInKazBox - find match log - #{matchLog}”
return true
else
puts “FAILED! issueCommandInKazBox - could not find match log -
#{matchLog}”
return false
end

end

But now with Ruby 1.9.2 and netssh 2.1.4. This doesn;t work.

So is it possible to install ruby 1.9.2 and then netssh 1.1.2 and then
while executing scripts i can direct script to use netssh 1.1.2
installed dir command so that above code works.

Currently it throws me error like :

  1. Error:
    test_0001(TC_I18N):
    NoMethodError: undefined method critical=' for Thread:Class C:/Ruby192/lib/ruby/site_ruby/1.9.1/needle/thread.rb:42:inlock’
    internal:prelude:8:in synchronize' C:/Ruby192/lib/ruby/site_ruby/1.9.1/needle/service-point.rb:117:ininstance

    C:/Ruby192/lib/ruby/site_ruby/1.9.1/needle/container.rb:308:in get' C:/Ruby192/lib/ruby/site_ruby/1.9.1/needle/registry.rb:124:inbootstrap’
    C:/Ruby192/lib/ruby/site_ruby/1.9.1/needle/registry.rb:106:in
    initialize' C:/Ruby192/lib/ruby/site_ruby/1.9.1/net/ssh/session.rb:265:innew’
    C:/Ruby192/lib/ruby/site_ruby/1.9.1/net/ssh/session.rb:265:in
    process_argum ents' C:/Ruby192/lib/ruby/site_ruby/1.9.1/net/ssh/session.rb:107:ininitialize’
    C:/Ruby192/lib/ruby/site_ruby/1.9.1/net/ssh.rb:50:in new' C:/Ruby192/lib/ruby/site_ruby/1.9.1/net/ssh.rb:50:instart’
    C:/IE_AUTOMATION/kazeon/qa/watir-v1_4-TIP/Lib/KazeonCommon/BasicMethodLibrar
    y.rb:873:in issueCommandInKazBox' C:/IE_AUTOMATION/kazeon/qa/watir-v1_4-TIP/KazModules/I18N/I18N_Regression.rb :78:intest_0001’

Bhavesh

Bhavesh S. wrote in post #1006480:

Is it possible to use previous gems to be used with Latest Ruby 1.9.2

Maybe. Depends on the gem. See http://isitruby19.com/

But now with Ruby 1.9.2 and netssh 2.1.4. This doesn;t work.
So is it possible to install ruby 1.9.2 and then netssh 1.1.2 and then
while executing scripts i can direct script to use netssh 1.1.2
installed dir command so that above code works.

Assuming the older gem is not 1.9.2 compatible, then no.

The better approach is to branch your code based on Ruby version
detection. Something along the line of:

if RUBY_VERSION.include?(“1.8”)

call method for 1.8

elsif RUBY_VERSION.include?(“1.9”)

call method for 1.9

end

– gw