From: Carl Jenkins on
unknown wrote:
> On Fri, Jul 23, 2010 at 2:28 PM, Carl Jenkins <carljenkins(a)gmail.com>
> wrote:
>>> but
>> �test/
>> �-new_test.rb
>>
>> In order to test the new_file.rb my new_test.rb must have the path to
>> the new_file.rb as the require correct? Something like require
>> '../lib/common/new_file'
>>
>> Or is there a different way to do that?
>
> Just looked at one of my bones-generated projects:
>
> $ cat spec/spec_helper.rb
>
> require File.expand_path(
> File.join(File.dirname(__FILE__), %w[.. lib fooz]))
> [...]

haha - that's genius..

(I should have known better and just looked myself.)

--
Posted via http://www.ruby-forum.com/.

From: Jarmo Pertman on
On Jul 23, 9:28 pm, Carl Jenkins <carljenk...(a)gmail.com> wrote:
> In order to test the new_file.rb my new_test.rb must have the path to
> the new_file.rb as the require correct? Something like require
> '../lib/common/new_file'
>
> Or is there a different way to do that?
>
> Thanks for all the help - (everyone) this is most helpful!

I would play with the $LOAD_PATH in your spec_helper or whatnot:

# spec_helper.rb
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "../lib"))

# blah_spec.rb
require "spec_helper" # require in every spec file
require "my_class" # now it's possible to require my_class from lib
dir because of changed $LOAD_PATH

describe MyClass do
it "test, test, test!" do
MyClass.new.should be
end
end

Or, if using really RSpec, then create a spec.opts file into the spec
directory and require it from there:
--require
spec_helper

Then you can remove those require statements from spec files
themselves. Although if you're using some kind of an IDE, then they
might get confused, but i don't mind :)

-----
Jarmo Pertman
IT does really matter - http://www.itreallymatters.net