Ruby Mock a file with StringIO
问题 I am trying to mock file read with the help of StringIO in Ruby. The following is my test and next to that is my method in the main class. def test_get_symbols_from_StringIO_file s = StringIO.new("YHOO,141414") assert_equal(["YHOO,141414"], s.readlines) end def get_symbols_from_file (file_name) IO.readlines(file_name, ',') end I want to know if this is the way we mock the file read and also I would like to know if there is some other method to mock the method in the class rather than doing