Forum: Ruby on Rails Generated test files and bad require 'test_helper'

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2009-05-14 22:23
Why do the generated test files have: require 'test_helper'

It cannot obviously find the file because it's located in a
subdirectory. That's annoying.
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-05-14 22:36
(Received via mailing list)
It finds it ok for me when run from rake test but not from ruby
test/unit/test.rb
I change all the require lines to

require File.dirname(__FILE__) + '/../test_helper'

I suspect there is a better way of achieving this effect

Colin

2009/5/14 Fernando Perez <rails-mailing-list@andreas-s.net>
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2009-05-14 22:50
Colin Law wrote:
> It finds it ok for me when run from rake test but not from ruby
> test/unit/test.rb
> I change all the require lines to
>
> require File.dirname(__FILE__) + '/../test_helper'
>
> I suspect there is a better way of achieving this effect
Thanks Colin for your input. Actually it works the same for me (I never
noticed), but I often find myself only running a little set of tests and
not always the full rake test.
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-05-14 23:21
(Received via mailing list)
Fernando Perez wrote:

> Colin Law wrote:

>> require File.dirname(__FILE__) + '/../test_helper'
>>
>> I suspect there is a better way of achieving this effect

> Thanks Colin for your input. Actually it works the same for me (I never
> noticed), but I often find myself only running a little set of tests and
> not always the full rake test.

Some editors run tests in the "wrong" folder - if they can run unit
tests at all
- so that File.dirname mishmash is crucial for Rails's tests. No idea
why the
newer version took it out!

--
   Phlip
   http://flea.sourceforge.net/resume.html
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-14 23:43
(Received via mailing list)
On May 14, 10:20 pm, Phlip <phlip2...@gmail.com> wrote:
> - so that File.dirname mishmash is crucial for Rails's tests. No idea why the
> newer version took it out!

Take a look at the comments for
http://github.com/rails/rails/commit/e8170805df1a3...

Fred
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-05-14 23:53
(Received via mailing list)
Frederick Cheung wrote:

>> Some editors run tests in the "wrong" folder - if they can run unit tests at all
>> - so that File.dirname mishmash is crucial for Rails's tests. No idea why the
>> newer version took it out!
>
> Take a look at the comments for 
http://github.com/rails/rails/commit/e8170805df1a3...

"different relative requires of the same file cause Ruby to load it
multiple
times. This causes bugs. Fixing it is the point of this change."

Then use File.expand_path(File.dirname(__FILE__) +
'/../test_helper.rb').

expand_path - if I spelled it right - goes to the OS filesystem for the
uniquely
correct path, right?

--
   Phlip
   http://flea.sourceforge.net/resume.html
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-05-14 23:56
(Received via mailing list)
> "different relative requires of the same file cause Ruby to load it multiple
> times. This causes bugs. Fixing it is the point of this change."
>
> Then use File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb').
>
> expand_path - if I spelled it right - goes to the OS filesystem for the uniquely
> correct path, right?

"File.expand_path doesn’t behave on Windows". It always comes back to
that, huh? (-:

--
   Phlip
   http://flea.sourceforge.net/resume.html
This topic is locked and can not be replied to.