我有以下结构:
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来实现它的优雅方式或最常用的方法是什么?
答案 0 :(得分:2)
您可以从my_class_spec.rb访问input1.txt的内容,如下所示:
file1_content = File.read(File.expand_path '../../inputs/input1.txt', __FILE__)