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.rbBut, 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
- How can this search pat开发者_如何学编程h be set?
- Where can such files be placed in the Rails project sources?
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'
精彩评论