开发者

Rails functional test file access

开发者 https://www.devze.com 2022-12-09 14:46 出处:网络
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

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 pat开发者_如何学编程h be set?
  2. 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'
0

精彩评论

暂无评论...
验证码 换一张
取 消