Reputation: 1015
I'm new to both ruby and rspec and I'm wondering how to test a class that must 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
In production I'll hard code the file's path. How should I control the file contents from rspec?
Upvotes: 3
Views: 3419
Reputation: 156444
Create a few specs which parse Tempfiles
that you create containing valid and invalid input and ensure that the parse function returns the expected results (or exceptions).
Upvotes: 2