[rspec-users] 'require'ing files from other directories

Wilker wilkerlucio at gmail.com
Thu Jan 20 16:20:00 EST 2011

Usually you can do some relative path requires, you can do it on your

require File.expand_path("../../lib/codebreaker", __FILE__)

or, another common setup is to add the "lib" into require path list, and
them just require the file:

$: << File.expand_path("../../lib", __FILE__)

require "codebreaker"

another hint: you should require only main file of lib (codebreaker), and
this file in lib should require the others (also, if you have some time,
research about autoload, will be useful too ;))
Wilker Lúcio
Kajabi Consultant
+55 81 82556600

On Thu, Jan 20, 2011 at 4:32 PM, Brian Warner <lists at ruby-forum.com> wrote:

> I'm going through The RSpec Book and am currently working with the
> Mastermind game example.
> But that's besides the point.
> The way my directories are setup is like so:
> /mastermind/features/step_definitions...
> /mastermind/lib/codebreaker/...
> I have a file in step_definitions that's giving me an error for an
> uninitialized constant. My guess is I need to 'require' the file where
> that class is defined. Said files is located in /lib/codebreaker.
> I am very new to Ruby so this is probably a really simple question but
> how do I 'require' a file in codebreaker from a file inside
> step_definitions?
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110120/2d7e9363/attachment.html>

More information about the rspec-users mailing list