David Kahn
2010-Dec-12 19:39 UTC
In Test/Unit Dir.glob is Rails root but to require a file must assume "Rails_root/test/"
I am wondering why this is: In Test/Unit I am iterating a directory so that
I can require each of the files in the directory.
When I call Dir.glob, the root is the Rails_root, however when I iterate the
files I get an error if I use Rails root and must begin the included
file''s
path from within the test directory.
This:
integration/helpers/file.rb
And not
test/integration/helpers/file.rb
I assume this is due somehow to Test/Unit running and having its own assumed
root directory in "test/" and not Rails root.
So is there a prettier method of doing this"
Dir.glob("test/integration/helpers/*.rb").each do |helper_file|
require helper_file.gsub(/test\//, '''') # for some
reason the Dir.glob
starts at rails root but when requiring, it starts within test/*
end
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Dec-12 22:42 UTC
Re: In Test/Unit Dir.glob is Rails root but to require a file must assume "Rails_root/test/"
On Dec 12, 7:39 pm, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote:> I am wondering why this is: In Test/Unit I am iterating a directory so that > I can require each of the files in the directory. > > When I call Dir.glob, the root is the Rails_root, however when I iterate the > files I get an error if I use Rails root and must begin the included file''s > path from within the test directory. >Require interprets paths relative to those folders on the load path. The root of the rails app isn''t on the load path, but test is, hence require ''test/integration/helpers/file'' doesn''t work, but require ''integration/helpers/file'' does. If you added that folder to load_paths & eager_load_paths then rails would require those files for you Fred> This: > > integration/helpers/file.rb > > And not > > test/integration/helpers/file.rb > > I assume this is due somehow to Test/Unit running and having its own assumed > root directory in "test/" and not Rails root. > > So is there a prettier method of doing this" > > Dir.glob("test/integration/helpers/*.rb").each do |helper_file| > require helper_file.gsub(/test\//, '''') # for some reason the Dir.glob > starts at rails root but when requiring, it starts within test/* > end-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Possibly Parallel Threads
- Dir.glob does not find ".project"
- Taking a stab at a pure Ruby Dir.glob
- [PATCH v2 1/2] daemon: glob: add optarg to control trailing slash for dirs
- Globbing inconsistencies, dir() vs. unlink()
- should Sys.glob() cope with a UNC windows path beginning with backslashes?