我有以下结构:
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
Run Code Online (Sandbox Code Playgroud)
我可以使用哪种优雅或最常用的方式来使用my_class_spec.rb中的input1.txt和input2.txt?
您可以从 my_class_spec.rb 访问 input1.txt 的内容,如下所示:
file1_content = File.read(File.expand_path '../../inputs/input1.txt', __FILE__)
Run Code Online (Sandbox Code Playgroud)