Gem loads in irb but not console

Hi!

I have the next problem: I was install a gem. The gem work well in
'irb', but doesn't work in console. What is the problem? Please, help!

Now, I print my 'step by step':
a.
root@iway-cacique:~# gem install selenium-webdriver
Successfully installed multi_json-1.5.0
Successfully installed rubyzip-0.9.9
Successfully installed ffi-1.3.1
Successfully installed childprocess-0.3.7
Successfully installed websocket-1.0.6
Successfully installed selenium-webdriver-2.29.0
6 gems installed

b.
root@iway-cacique:~# irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'selenium-webdriver'
=> true

c.
root@iway-cacique:~# ruby -e 'require "rubygems"'
root@iway-cacique:~# ruby -e 'require "selenium-webdriver"'
-e:1:in `require': no such file to load -- selenium-webdriver
(LoadError)
        from -e:1

···

########################
#Additional Information#
########################

root@iway-cacique:~# irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> Gem.path
=> ["/usr/lib/ruby/gems/1.8", "/root/.gem/ruby/1.8"]
------------------------

root@iway-cacique:~# gem which 'selenium-webdriver'
/usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.29.0/lib/selenium-webdriver.rb
------------------------

root@iway-cacique:~# bundle show selenium-webdriver
/usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.29.0
------------------------

root@iway-cacique:~# ruby --version
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
------------------------

root@iway-cacique:~# rails --version
Rails 2.3.9
------------------------

root@iway-cacique:~# gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.25
  - RUBY VERSION: 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /usr/bin/ruby1.8
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.8
     - /root/.gem/ruby/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

--
Posted via http://www.ruby-forum.com/.

running 2 separate ruby commands creates 2 separate processes

either put the code into a file and run the file

or put both requires in a single -e parameter

···

On Fri, Jan 25, 2013 at 10:14 AM, Martin Kociman <lists@ruby-forum.com>wrote:

Hi!

I have the next problem: I was install a gem. The gem work well in
'irb', but doesn't work in console. What is the problem? Please, help!

Now, I print my 'step by step':
a.
root@iway-cacique:~# gem install selenium-webdriver
Successfully installed multi_json-1.5.0
Successfully installed rubyzip-0.9.9
Successfully installed ffi-1.3.1
Successfully installed childprocess-0.3.7
Successfully installed websocket-1.0.6
Successfully installed selenium-webdriver-2.29.0
6 gems installed

b.
root@iway-cacique:~# irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'selenium-webdriver'
=> true

c.
root@iway-cacique:~# ruby -e 'require "rubygems"'
root@iway-cacique:~# ruby -e 'require "selenium-webdriver"'
-e:1:in `require': no such file to load -- selenium-webdriver
(LoadError)
        from -e:1

########################
#Additional Information#
########################

root@iway-cacique:~# irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> Gem.path
=> ["/usr/lib/ruby/gems/1.8", "/root/.gem/ruby/1.8"]
------------------------

root@iway-cacique:~# gem which 'selenium-webdriver'

/usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.29.0/lib/selenium-webdriver.rb
------------------------

root@iway-cacique:~# bundle show selenium-webdriver
/usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.29.0
------------------------

root@iway-cacique:~# ruby --version
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
------------------------

root@iway-cacique:~# rails --version
Rails 2.3.9
------------------------

root@iway-cacique:~# gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.25
  - RUBY VERSION: 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /usr/bin/ruby1.8
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.8
     - /root/.gem/ruby/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

--
Posted via http://www.ruby-forum.com/\.

Hi!

I have the next problem: I was install a gem. The gem work well in
'irb', but doesn't work in console. What is the problem? Please, help!

...

root@iway-cacique:~# irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'selenium-webdriver'
=> true

c.
root@iway-cacique:~# ruby -e 'require "rubygems"'
root@iway-cacique:~# ruby -e 'require "selenium-webdriver"'
-e:1:in `require': no such file to load -- selenium-webdriver
(LoadError)
        from -e:1

When you use IRB, you have a single ruby interpreter running, which executes
all your commands. So you tell this interpreter first to load rubygems, then
to load selenium-webdriver. And all is well. When you use the console, you
execute the ruby program twice, which means you get two copies of the
interpreter. You first start an interpreter and tell it to load rubygems. It
does that, then it closes, not having anything else to do. Then, you launch
ruby again and this time tell it to load selenium-webdriver. Now, this second
interpreter has nothing in common with the previous one; in particular, it
hasn't loaded rubygems. Hence the error.

I don't know what exactly you're trying to accomplish, since ruby is usually
used with the -e switch only for very short scripts. If you want something
longer, you usually use irb, write the script to a file and pass it to ruby,
as

ruby my_script.rb

or type it directly into ruby (which, however, is quite akward):
ruby
require 'rubygems'
require 'selenium-webdriver'
...

Note that to have your code executed, you'll have to send a Ctrl+D character.

If you really want to use the -e switch, then you should also use the -r
switch, which allows to specify libraries to require before executing the
script. In your case, you could do the following:

ruby -rrubygems -e 'require "selenium-webdriver'"

Note that in ruby 1.8, you can't use the -r switch to require gems. For
example, this wouldn't have worked:

ruby -rrubygems -rselenium-webdriver -e '...'

Also, there is a file called ubygems.rb in your rubygems installation which
simply requires rubygems and which allows to write

ruby -rubygems -e 'require "selenium-webdriver'"

instead of -rrubygems.

I hope this helps

Stefano

···

On Saturday 26 January 2013 Martin Kociman wrote

Chris, Stefano, thanks for the response, but the problem is other. In
other words: Gem loads in irb but not in ECLIPSE

I've a script IN ECLIPSE (not console), that starts with:

require 'rubygems'
require 'selenium-webdriver'

The script return the next error:
no such file to load -- selenium-webdriver

The problem is: In IRB, the commands work OK, but in Eclipse only
"require 'rubygems'" is working ok. When is executed "require
'selenium-webdriver'" appears the error.

I think that is a problem with gems and versions of ruby, but how I
resolve the problem?

Additional data: It's the same that in my first comment.

Thanks,
Martin

···

--
Posted via http://www.ruby-forum.com/.