Testing with input files in rspec. How to organize?

I have the following structure:

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 

What is an elegant way or the most common way that I can do so that I can use input1.txt and input2.txt in my_class_spec.rb?

+4
source share
1 answer

You can access the contents of input1.txt from my_class_spec.rb as follows:

 file1_content = File.read(File.expand_path '../../inputs/input1.txt', __FILE__) 
+2
source

Source: https://habr.com/ru/post/1443425/


All Articles