views:

51

answers:

1

I need to access a file in a Rails functional test in test/functional/main_controller_test.rb. If I mention the file within "", and the included file is placed in test/ directory, I can run the test using:

$ cd test
$ ruby functional/main_controller_test.rb

But, I get a cannot find file error, when I use it from the top-level Rails project sources:

$ rake test:functionals

Errno::ENOENT: No such file or directory

  1. How can this search path be set?
  2. Where can such files be placed in the Rails project sources?
+2  A: 

You can reference a file relative to the current file (i.e. main_controller_test.rb) like this:

data_file_path = File.dirname(__FILE__) + '/../data_file.txt'
Olly