5

我有以下结构:

MyProject --> Main folder of my project.
MyProject/my_class.rb
MyProject/inputs/input1.txt
MyProject/inputs/input2.txt
MyProject/rspec/spec_helper.rb
MyProject/rspec/my_class_spec.rb

什么是一种优雅的方式或最常见的方式,以便我可以在 my_class_spec.rb 中使用 input1.txt 和 input2.txt?

4

1 回答 1

2

您可以像这样从 my_class_spec.rb 访问 input1.txt 的内容:

file1_content = File.read(File.expand_path '../../inputs/input1.txt', __FILE__)
于 2012-11-01T12:22:54.683 回答