2012-11-01 20 views
4

我有以下結構:使用rspec中的輸入文件進行測試。如何組織?

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?

回答

2

您可以從my_class_spec.rb這樣的訪問input1.txt的內容:

file1_content = File.read(File.expand_path '../../inputs/input1.txt', __FILE__) 
相關問題