# Require wackyness

**URL:** <https://www.ruby-forum.com/t/require-wackyness/156796>\
**Category:** Ruby\
**Created:** [January 3, 2009, 12:38am UTC](https://www.ruby-forum.com/t/require-wackyness/156796 "2009-01-03T00:38:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spobo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f4b2a3/32.png) [@spobo](https://www.ruby-forum.com/u/spobo)\
**Post date:** [January 3, 2009, 12:38am UTC](https://www.ruby-forum.com/t/require-wackyness/156796/1 "2009-01-03T00:38:03Z")

</div>

Hi,

First time poster here … picking up Ruby again after neglecting it for

> 2 years after some rails work. But, instead of Rails, this time I want  
> to properly understand Ruby. Sadly though progress is slow … mainly  
> due to the following problem:

I have a root directory containing 2 folders (lib & spec). lib contains  
a couple of sub-folders and I want all of the folders known to Ruby so  
that it knows where to look when I require the files. But somehow this  
isn’t working. Probably making a beginner mistake … Here is what I  
have:

lib/classes/movie.rb:

class Movie  
#…  
end

spec/spec\_helper.rb:

paths = %w(classes, logic, logic/scrapers)  
paths.each do |p|  
$LOAD\_PATH \<\<  
File.expand\_path("#{File.dirname( **FILE** )}/…/lib/#{p}")  
end  
puts $LOAD\_PATH

spec/imdb\_movie\_scraper\_spec.rb:

$LOAD\_PATH \<\< File.expand\_path(File.dirname( **FILE** ))

require ‘spec\_helper’  
require ‘imdb\_movie\_scraper’  
require ‘movie’  
#…

Here is what I do:  
in the root directory (directory containing lib and spec):  
spec spec/imdb\_movie\_scraper\_spec.rb -c

and it gives me the following annoying error:  
/Library/Ruby/Site/1.8/rubygems/custom\_require.rb:31:in  
`gem_original_require': no such file to load -- movie (LoadError) from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in`require’  
from ./spec/imdb\_movie\_scraper\_spec.rb:6 (yes, this is include ‘movie’

I know that spec\_helper launched since it outputs the $LOAD\_PATH just  
above the error.

HOW is this possible? The file movie.rb is obviously defined in  
/Users/spobo/Code/movie-crawler/lib/classes and this is included in  
$LOAD\_PATH.

What am I missing here? Debugging and figuring out this stuff any longer  
and my shiny new laptop will go from 60 to 0 in 0.01 second flat against  
the wall. _aaaaaaaar_ it’s frustrating!!

---

<div class="post-metadata">

**Author:** ![spobo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f4b2a3/32.png) [@spobo](https://www.ruby-forum.com/u/spobo)\
**Post date:** [January 3, 2009, 1:44am UTC](https://www.ruby-forum.com/t/require-wackyness/156796/2 "2009-01-03T01:44:07Z")

</div>

On Jan 2, 2009, at 6:37 PM, Vincent Ds wrote:

> contains
> 
> spec/spec\_helper.rb:
> 
> paths = %w(classes, logic, logic/scrapers)  
> You almost certainly do not want those commas:  
> paths = %w( classes logic logic/scrapers)
> 
> /Library/Ruby/Site/1.8/rubygems/custom\_require.rb:31:in  
> /Users/spobo/Code/movie-crawler/lib/classes and this is included in  
> $LOAD\_PATH.
> 
> ## What am I missing here? Debugging and figuring out this stuff any longer and my shiny new laptop will go from 60 to 0 in 0.01 second flat against the wall. _aaaaaaaar_ it’s frustrating!!

If you want _all_ the directories under lib/ to be in the LOAD\_PATH,  
you could do:

Dir[‘…/lib/ **/** ’].each do |dir|  
$LOAD\_PATH \<\< File.expand\_path(dir)  
end  
puts $LOAD\_PATH

Then you’d pick up ALL the future directories under lib/, too!

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![spobo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f4b2a3/32.png) [@spobo](https://www.ruby-forum.com/u/spobo)\
**Post date:** [January 3, 2009, 1:38pm UTC](https://www.ruby-forum.com/t/require-wackyness/156796/3 "2009-01-03T13:38:04Z")

</div>

Rob B. wrote:

> On Jan 2, 2009, at 6:37 PM, Vincent Ds wrote:
> 
> > contains
> > 
> > spec/spec\_helper.rb:
> > 
> > paths = %w(classes, logic, logic/scrapers)  
> > You almost certainly do not want those commas:  
> > paths = %w( classes logic logic/scrapers)
> > 
> > /Library/Ruby/Site/1.8/rubygems/custom\_require.rb:31:in  
> > /Users/spobo/Code/movie-crawler/lib/classes and this is included in  
> > $LOAD\_PATH.
> > 
> > ## What am I missing here? Debugging and figuring out this stuff any longer and my shiny new laptop will go from 60 to 0 in 0.01 second flat against the wall. _aaaaaaaar_ it’s frustrating!!
> 
> If you want _all_ the directories under lib/ to be in the LOAD\_PATH,  
> you could do:
> 
> Dir[‘…/lib/ **/** ’].each do |dir|  
> $LOAD\_PATH \<\< File.expand\_path(dir)  
> end  
> puts $LOAD\_PATH
> 
> Then you’d pick up ALL the future directories under lib/, too!
> 
> -Rob
> 
> Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> removed\_email\_address@domain.invalid  
> Aha!

Rob, Thx! It was indeed the beginner mistake of using the commas where  
there shouldn’t be any. The ways of other programming languages are  
still blocking my thinking 😛

The suggestion you made of including every directory under lib… looks  
good. I’ll try it out. Thx for restoring my fait in Ruby 😃 I knew it  
had to be me and not Ruby that was playing tricks on me 😛
