7

I am new to Ruby and would really appreciate some help understanding what is going on here.
Summary:

Gem install watir-webdriver
Installs fine
start irb
require "watir-webdriver"
... LoadError: no such file to load --watir-webdriver

Surely this should respond

=> true

Why is it not finding the gem? Or what am I doing wrong?

Console

I'm on win7, Railsinstaller (Ruby 1.8.7).

Chuck van der Linden
  • 6,660
  • 2
  • 28
  • 43
Dirk
  • 3,073
  • 4
  • 31
  • 36

3 Answers3

13

In 1.8.7 you need to require rubygems first.

require 'rubygems'

Some explanation here: How does require rubygems help find rubygem files?

Community
  • 1
  • 1
Steve
  • 15,606
  • 3
  • 44
  • 39
5

Depending on your setup, you might need to require 'rubygems' first, like so:

$ irb
>> require 'rubygems'; require 'watir-webdriver'
=> true
muffinista
  • 6,676
  • 2
  • 30
  • 23
3

In Ruby 1.8.7, require won't locate gems unless you do require 'rubygems' first. (Ruby 1.9 loads gems without this.)

I highly, highly recommend using Bundler for managing gem dependencies. If you weren't on Windows, I'd recommend RVM as well; I understand that Pik may do something similar for Windows, but I've never used it.

Marnen Laibow-Koser
  • 5,959
  • 1
  • 28
  • 33
  • Thanks. I'm taking a look at Pik now. – Dirk Nov 09 '11 at 15:09
  • Pik doesn't let you define sets of gems the way RVM does, but it does make it easy to juggle back and forth between versions of ruby, each with its own set of gems. (it can also duplicate a set of gems from one version to another). Great for when you want to 'move up' to a new version of ruby and run both at the same time (alternatively) on the same system. – Chuck van der Linden Nov 09 '11 at 18:00
  • If you're using Bundler, you don't really need RVM gemsets (though I often use both together). – Marnen Laibow-Koser Nov 09 '11 at 19:18