While writing tests sometimes we need to read files to compare the output. For example a test might want to compare the API response with pre determined data stored in a file. Here is an example. 1 2# In test helper 3def file_data(name) 4 File.read(Rails.root.to_s + "/tests/support/files/#{name}") 5end 6 7# In test 8class PostsControllerTest < ActionDispatch::IntegrationTest 9 setup do 10 @post =