Ruby - require 'watir-webdriver' - generates a LoadError no such file... Why?
Asked Answered
H

3

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

Homograph answered 9/11, 2011 at 13:52 Comment(1)
To avoid problems like that, read free version of my watir book: github.com/zeljkofilipin/watirbook/downloadsMolality
T
13

In 1.8.7 you need to require rubygems first.

require 'rubygems'

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

Twowheeler answered 9/11, 2011 at 13:54 Comment(0)
S
5

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

$ irb
>> require 'rubygems'; require 'watir-webdriver'
=> true
Sherwoodsherwynd answered 9/11, 2011 at 13:54 Comment(0)
C
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.

Contredanse answered 9/11, 2011 at 15:1 Comment(3)
Thanks. I'm taking a look at Pik now.Homograph
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.Hamman
If you're using Bundler, you don't really need RVM gemsets (though I often use both together).Contredanse

© 2022 - 2024 — McMap. All rights reserved.