# ""no such file to load -- test\_helper"

**URL:** <https://www.ruby-forum.com/t/no-such-file-to-load-test-helper/170558>\
**Category:** Rails\
**Created:** [June 18, 2009, 11:23pm UTC](https://www.ruby-forum.com/t/no-such-file-to-load-test-helper/170558 "2009-06-18T23:23:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 18, 2009, 11:23pm UTC](https://www.ruby-forum.com/t/no-such-file-to-load-test-helper/170558/1 "2009-06-18T23:23:49Z")

</div>

I have seen a lot of discussions about the issue where if you run a  
unit test from the command line you get the error:

“no such file to load – test\_helper”

I have been using the workaround of changing:

require ‘test\_helper’

to:

require File.dirname( **FILE** ) + ‘/…/test\_helper’

I’m hoping there is a better way? Maybe a fix in edge rails? Anyone  
have an update?

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 18, 2009, 11:26pm UTC](https://www.ruby-forum.com/t/no-such-file-to-load-test-helper/170558/2 "2009-06-18T23:26:10Z")

</div>

2009/6/18 TomRossi7 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> to:
> 
> require File.dirname( **FILE** ) + ‘/../test\_helper’
> 
> I’m hoping there is a better way? Â Maybe a fix in edge rails? Â Anyone  
> have an update?

The recommended way of avoiding this issue is to use  
ruby -I test test/unit/whatever.rb

Apparently putting the dirname in the require can cause all sorts of  
issues that I do not understand and we just have to put up with it. (  
I don’t mean we have to put up with not understanding it).  
I must admit that since I have never come across any of those issues I  
just put the dirname in. My projects are personal rather than  
commercial however so the fact that I may fall over this some day is  
my problem only. I think if I were doing a commercial app I would  
probably not put the dirname in, and put up with it.

Colin

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 19, 2009, 12:07am UTC](https://www.ruby-forum.com/t/no-such-file-to-load-test-helper/170558/3 "2009-06-19T00:07:45Z")

</div>

Colin L. wrote:

> > require File.dirname( **FILE** ) + ‘/../test\_helper’
> > 
> > I’m hoping there is a better way? Maybe a fix in edge rails? Anyone  
> > have an update?
> 
> The recommended way of avoiding this issue is to use  
> ruby -I test test/unit/whatever.rb

How to get that inside your rake test script?

> Apparently putting the dirname in the require can cause all sorts of  
> issues that I do not understand and we just have to put up with it. (  
> I don’t mean we have to put up with not understanding it).

require ‘../foo’ and require ‘../../bar/foo’ will both load foo.rb  
twice. This  
is usually not what you want, but it’s a simplification in the current  
require  
system. Because all unit tests should run in the same VM, the ones in  
different  
folders will load test\_helper again.

Won’t this fix it?

$:.unshift File.dirname( **FILE** ) + ‘/../’  
require ‘test\_helper’

Then the second occurrence of require ‘test\_helper’ will not load twice,  
even if  
(on some dementedly configured system), the require  
File.dirname( **FILE** ) +  
‘/../test\_helper’ could have instead loaded a different one.

–  
Phlip

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 19, 2009, 12:52am UTC](https://www.ruby-forum.com/t/no-such-file-to-load-test-helper/170558/4 "2009-06-19T00:52:13Z")

</div>

This works for me:

require File.dirname( **FILE** ) + ‘/…/test\_helper’

I just wish I didn’t have to keep editing my test files. It sounds  
like there still isn’t a consensus on a workaround or a fix in the  
works from the Rails Core.

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 19, 2009, 9:00am UTC](https://www.ruby-forum.com/t/no-such-file-to-load-test-helper/170558/5 "2009-06-19T09:00:03Z")

</div>

2009/6/18 Phlip [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> How to get that inside your rake test script?

You don’t, the OP referred to the problem that if you run a unit test  
from the command line you get the error. If instead of running the  
unit test by

ruby test/unit/whatever.rb

you use

ruby -I test test/unit/whatever.rb

the error does not appear as the test directory is included in the ruby  
path.

The problem does not appear in the first place when using rake test

Colin
