require wackyness

V

Vincent Ds

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!!
 
R

Rob Biedenharn

Hi,

First time poster here ... picking up Ruby again after neglecting it
for
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)
You almost certainly do not want those commas:
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!!
--


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 Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 
V

Vincent Ds

Rob said:
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 Biedenharn http://agileconsultingllc.com
(e-mail address removed)
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 :p

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top