I'm working on this Exercise 49 in Learn Ruby the Hard Way
The exercise asks to write a unit test for each function provided. One of the unit tests I am writing is giving me an error.
Here is the code I am testing (word_list is an array of Pair structs)
Pair = Struct.new(:token, :word)
def peek(word_list)
begin
word_list.first.token
rescue
nil
end
end
def match(word_list, expecting)
begin
word = word_list.shift
if word.token == expecting
word
else
nil
end
rescue
nil
end
end
def skip(word_list, token)
while peek(word_list) == token
match(word_list, token)
end
end
Here is the test:
def test_skip
small_list = [Pair.new(:verb, 'go'), Pair.new(:verb, 'do')]
skip(small_list, :verb)
assert_equal([],small_list)
end
Here is the error I get when I run the unit test:
1) Error:
test_skip(SentenceTests):
TypeError: backtrace must be Array of String
test_sentence.rb:23:in `test_skip'
In this case, line 23 refers to "skip(small_list, :verb)". I am not sure why this error is happening, the above two functions were unit tested as well and those tests came out fine.
@Zabba, I did put them exactly as specified in the exercise above:
class ParserError < Exception
end
If anyone needs to see the exact files I am using here is the link to a gist: https://gist.github.com/1190148