Search code examples
rubyrspecshoulda

How do I write a unit test for a method which removes characters from a text file?


I need to unit test a method which removes all the special characters like ,, : and some blank spaces.

The method under test stores each line of the file in a separate array position.

How do I test if the method removed all the special characters of a text file?


Solution

  • Write the file after your method call and use regex to ensure there are no special characters you don't want. Or compare file contents against a file that contains the result you wish to achieve.