Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test with input files in rspec. How to organize?

Tags:

ruby

rspec

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 most common way that I can make it so that I can use the input1.txt and input2.txt in my_class_spec.rb?

like image 466
Hommer Smith Avatar asked Nov 04 '22 12:11

Hommer Smith


1 Answers

You can access content of input1.txt from my_class_spec.rb like this:

file1_content = File.read(File.expand_path '../../inputs/input1.txt', __FILE__)
like image 187
Victor Deryagin Avatar answered Nov 08 '22 04:11

Victor Deryagin