Exercise 49 of Learn Ruby the Hard Way you’re required to write the tests based on the code given to you. After working through the last exercise, this somehow made a lot more sense.
I used the Ruby docs Module on Test::Unit::Assertions for this exercise. I stuck to the assert_equal and assert_not_equal methods to test whether the ‘expected was equal to actual’ or ‘not equal to actual’ respectively and the assert_raise method to raise an exception.
The assert_raise method was tricky to work with initially as there weren’t many beginner level friendly code examples but with a bit of trial and error we got there.
The code provided in the book also required a bit of tweaking so the test file would run. Here are some examples of my test code for the exercise 49.
parsing a subject
parser.rb
test_parser.rb
parsing a sentence
parser.rb
test_parser.rb
comments powered by