RSpec: how to check file parser

I am new to ruby โ€‹โ€‹and rspec, and I am wondering how to test a class that should parse a file. Here is the function I plan to test:

def self.get_description(event_code)
  # search through a file for the event_code and return
  # the associated description field
end

During production, I will hard-code the file path. How can I control the contents of a file from rspec?

+3
source share
1 answer

Create some specifications that process Tempfilesthat you create that contain valid and invalid input, and ensure that the parsing function returns the expected results (or exceptions).

+2
source

All Articles